jamanat
asked on
function overloading
why c++ does not allow =,(),[],-> to be overloaded as friend function?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
operator [] is simlar to (), agan it is to force you to put an object to the left of the []. Although in this case there would be no syntacitc confussions as
int y = [x];
is not currently legal.
I'm not sure why operator -> would have to have this restriction. it seems like it could be written as a non-member that takes a single parameter that must be a user-defined class type.
int y = [x];
is not currently legal.
I'm not sure why operator -> would have to have this restriction. it seems like it could be written as a non-member that takes a single parameter that must be a user-defined class type.
ASKER
Hey thanks for answering my question. But I need some more help on this. Can you mail me on jamanat@usa.net?
please....
please....
Why e-mail? Is there any reason you cannot ask here? Information posted here will be saved in EE's database for future queries.
int operator(int i) { return i +1; };
int x = 1;
int y = (int) x;
does that code just cast an int to an int, which does nothing, or does it call that overloaded operator ()? You can't tell, but as a member function an object will always appear to the left of the parenthesis to make this clear.
continues