While overloading operator*
we do as follows:
T & operator * () { return *ptr; }
That means if I have:
SmartPtr<int> obj(new int());
*Obj = 20;
Cout << *obj;
Then the *obj
part is replaced by *ptr
so its as good as:
*Ptr=20
cout<<*ptr
Now while overloading operator->
we do the following:
T * operator -> () { return ptr; }
And it can be accessed as:
Obj->myfun();
What I don't understand here is after evaluating the obj->
is replaced by ptr
so it should look as follows:
ptrmyfun(); // and this is syntax error
Where am I going wrong?