Overload ->, a pointer to the invoking object. - C++ Class

C++ examples for Class:Operator Overload

Description

Overload ->, a pointer to the invoking object.

Demo Code

#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;
}

Result


Related Tutorials