0

Possible Duplicate:
What is the difference between the dot (.) operator and -> in C++?

C++ has the following member selection operators: . and ->.

What is the main difference between them?

Thanks.

Community
  • 1
  • 1
Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • 2
    this question has already been asked here - http://stackoverflow.com/questions/1238613/what-is-the-difference-between-the-dot-operator-and-in-c – Bojan Komazec Feb 13 '11 at 12:25
  • That question is also a duplicate of http://stackoverflow.com/questions/221346/what-is-the-arrow-operator-synonym-for-in-c – The Scrum Meister Feb 13 '11 at 12:29

2 Answers2

1

. is used with non-pointers, while -> is used with pointers, to access members!

Sample s;
Sample *pS = new Sample();

s.f() ;  //call function using non-pointer object
pS->f(); //call the same function, using pointer to object

. cannot be overloaded, while -> can be overloaded.

Nawaz
  • 353,942
  • 115
  • 666
  • 851
1

pointer2object->member() is equal to (*pointer2object).member() and is made for more convinience, as I suppose.

Kos
  • 364
  • 2
  • 3