C++ examples for Class:Operator Overload
Overload ->, a pointer to the invoking object.
#include <iostream> using namespace std; class myclass {//w w w . j a v a 2 s. com public: int i; // Overload -> to return a pointer to the invoking object. myclass *operator->() { return this; } }; int main() { myclass ob; ob->i = 10; // same as ob.i cout << ob.i << " " << ob->i; return 0; }