0

Possible Duplicate:
C++: ptr->hello(); /* VERSUS */ (*ptr).hello();

Too bad I can't google this...

Could someone explain or point me to where I can find the difference between these two? I understand * is a dereferencing operator, what about the -> ? What's the difference?

Community
  • 1
  • 1
dukevin
  • 21,107
  • 35
  • 78
  • 109

2 Answers2

4

a->b is a syntactic sugar for (*a).b

The only special case is the object operator-> which is called when -> is used on an object. It can be used to "simulate" the object is a pointer ( as with smart references )

crazyjul
  • 2,469
  • 17
  • 25
4

In the absence of overloading operator->, p->x is equivalent to (*p).x

Stuart Golodetz
  • 19,702
  • 4
  • 49
  • 80