What's wrong with opCall ?

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Nov 28 06:43:50 PST 2010


Hello,

Considering my effort on rework of the range API for upcoming 
std.datetime (It's coming, Jonathan, but far slower then I thought).
I was in determined to see where can I get with function-like objects, 
but it seems I'm missing something.
The following program do not compile:
struct S{
     ubyte _d;
     this(ubyte d){
         _d = d;
     }
     int opCall(string a){
         return  _d;
     }
}

void main(){
     S s = S(22);
     assert(s.opCall("A") == 22);
//    s("A");//uncoment to get compile error
}

bug.d(14): Error: constructor bug.S.this (ubyte d) is not callable using 
argument types
bug.d(14): Error: cannot implicitly convert expression ("A") of type 
string to ubyte

So it appears that compiler views it as a call to constructor instead. 
What's the problem?

-- 
Dmitry Olshansky



More information about the Digitalmars-d mailing list