Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

overloading operator->

Status
Not open for further replies.

chipperMDW

Programmer
Mar 24, 2002
1,268
US
Say I have:

Code:
template< class T >
class SmartPtr
{
  public:
    ...
    T *operator->() { return ptr; }

  private:
    T *ptr;
};


This works (and is apparently the/a correct way of doing it), but I don't understand the logic behind having the operator return a pointer.

Given:

Code:
SmartPtr< FooStruct > p = &someFooStruct;


that means:

Code:
p->fooStructMember;


roughly translates to:

Code:
( &someFooStruct ) fooStructMember;


which looks like it's missing a -> . Does another operator-> get called behind the scenes for the return value of operator-> ? If not, what exactly is going on here?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top