# operator under C implementation in D1

Sergey Gromov snake.scaly at gmail.com
Sat Mar 14 16:39:59 PDT 2009


Thu, 12 Mar 2009 23:44:40 -0400, Sam Hu wrote:

> Here I found an example form tango.io.Console class Output:
> class Output
>         {
>                 private Buffer  buffer;
>                 private bool    redirect;
> 
>                 public  alias   append opCall;
>                 public  alias   flush  opCall;
> 
>                 final Output append (char[] x)
>                 {
>                         buffer.append (x.ptr, x.length);
>                         return this;
>                 } 
> ...
> }
> On above code,
>  public  alias   append opCall;
>  public  alias   flush  opCall;
> 
> How can we do things like this since the opCall is the system defined?
> Thanks.

You are correct in that it's impossible to re-alias an existing type.
Your previous example with Color won't compile.  Where you are wrong is
in assumption that opCall is "system defined."  It is not, actually.
Compiler just searches for a function with this name.  It uses one if
found, or performs a default action otherwise.  There is *no*
compiler-generated opCall.

In this example, opCall is made a synonym for append and for flush:

Output o = ...;
o(); // equivalent to o.flush()
o("string"); // equivalent to o.append("string")


More information about the Digitalmars-d-learn mailing list