Why are opCall's not implicitely assignable?

Stewart Gordon smjg_1998 at yahoo.com
Wed Sep 20 11:49:45 PDT 2006


Karen Lanrap wrote:
> class C{
>     int opCall(int i){
>       return 2*i;
>     }
> }
> 
> int main(){
>     auto c= new C;
>     int x=c.opCall=3; // compiles
>     int x=c=3; // does not compile
> }

Because the expression form has nothing to do with opCall whatsoever.

The purpose of opCall is specifically to overload the (...) form to make 
the class act like a function.  There's no reason that the property 
syntactic sugar should apply to an object of the class being used as a 
function.  If it did, then how would you assign object references of 
classes that have opCall at all?

Similarly,

     void function(int) qwert;
     ...
     qwert(yuiop);   // calling the pointed-to function
     qwert = asfdg;  // changing which function is pointed to

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.



More information about the Digitalmars-d-learn mailing list