Why are opCall's not implicitely assignable?

Hasan Aljudy hasan.aljudy at gmail.com
Wed Sep 20 12:52:06 PDT 2006



Stewart Gordon wrote:
> 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.
> 

Something bugs me here .. there's some level of inconsistency with all 
the stuff related to property syntax sugar.



More information about the Digitalmars-d-learn mailing list