Operator Overloading
-
Hi All, I have a structure that contains a list of function delegates. Each of the delegates do something different. Depending on how the parent class is initialised, depends on which of delegates is populated. Now the question is, can I overload the '->' operator, so that the calling code can call one of the delegates in the structure by calling the same name. e.g.
class X { struct y { fastdelegate someMemberDelegateOfY; ... } ... } { X myX; myX->someMemberDelegateOfY (parameters,for,delegate,in,struct,y); }
Then when the code executes, it will call the delegate in the structure. Is this possible, and if so how? thanks, Rich
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook
-
Hi All, I have a structure that contains a list of function delegates. Each of the delegates do something different. Depending on how the parent class is initialised, depends on which of delegates is populated. Now the question is, can I overload the '->' operator, so that the calling code can call one of the delegates in the structure by calling the same name. e.g.
class X { struct y { fastdelegate someMemberDelegateOfY; ... } ... } { X myX; myX->someMemberDelegateOfY (parameters,for,delegate,in,struct,y); }
Then when the code executes, it will call the delegate in the structure. Is this possible, and if so how? thanks, Rich
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook
-
Hi All, I have a structure that contains a list of function delegates. Each of the delegates do something different. Depending on how the parent class is initialised, depends on which of delegates is populated. Now the question is, can I overload the '->' operator, so that the calling code can call one of the delegates in the structure by calling the same name. e.g.
class X { struct y { fastdelegate someMemberDelegateOfY; ... } ... } { X myX; myX->someMemberDelegateOfY (parameters,for,delegate,in,struct,y); }
Then when the code executes, it will call the delegate in the structure. Is this possible, and if so how? thanks, Rich
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook
RichardS wrote:
Is this possible, and if so how?
Yes.
class X { public: int getInt() { return 0; } }; class Y { public: X* operator->() { return &_x; } private: X _x; }; int main() { Y y; return y->getInt(); }
The restriction on overloading -> is that it must return a pointer of some kind.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
RichardS wrote:
Is this possible, and if so how?
Yes.
class X { public: int getInt() { return 0; } }; class Y { public: X* operator->() { return &_x; } private: X _x; }; int main() { Y y; return y->getInt(); }
The restriction on overloading -> is that it must return a pointer of some kind.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac