I was trying to implement a smart pointer class similar to the standard library auto_ptr and accordingly I had to overload the -> operator for the same. Here is my code
template <typename T>
class SmartPtr
{
T * operator -> ()
{
return _pAct;
}
private:
T * _pAct;
};
Rest of the implementation is not shown so as to avoid diversion from my query.
Now I create a SmartPtr of class A and call a method Show() present in A on it :
SmartPtr smPtr(new A);
smPtr->Show();
Here is my query(don't know if its valid also)
Since SmartPtr::operator->() return A*, the call to show should translate to (A*)Show. Why it translates to (A*)->Show() ?
or in other words how does smPtr->Show() mean call Show() on whatever smPtr->() operator returns ?