declaration/expression

Michal Minich michal.minich at gmail.com
Tue Jun 23 01:08:29 PDT 2009


> import tango.io.Stdout;
> void main(){
>     int[4] i = [1,2,3,4];
>     T(t); // compiler: I think this is an expression *barf* t(i[])(i[]);
>     //compiler: I think this is a declaration *barf*
> }
> 
> class T{
>     public T opCall(int[] i){
>         Stdout(i).newline;
>         return this;
>     }
> }

In your example are at least two errors.

T(t); -- the "t" is not defined there
public T opCall(int[] i) { -- it should be called as t(i), if you want 
call T(i), make this method static.

I personally do not encounter problem you are writing about. But you 
should be aware of: Expressions that have no effect, like (x + x), are 
illegal in expression statements. If such an expression is needed, 
casting it to void will make it legal. 

http://www.digitalmars.com/d/1.0/statement.html#ExpressionStatement



More information about the Digitalmars-d mailing list