Meaning of "->"

What it the meaning of ->. I the code I have to analyze I find a line
variable->function(other variable);
It is the same as the '.' operator except the variable is a pointer.

http://www.cplusplus.com/doc/tutorial/classes/

Go to the bottom


expression can be read as
*x pointed to by x
&x address of x
x.y member y of object x
x->y member y of object pointed to by x
(*x).y member y of object pointed to by x (equivalent to the previous one)
x[0] first object pointed to by x
x[1] second object pointed to by x
x[n] (n+1)th object pointed to by x
Thank you giblit.

1
2
3
4
5
6
  void AddressPool::AddElement (PoolElementPointer ptr)
  {
  ptr->nextElem = poolTable;
  poolTable = ptr;
  }


Am I right, that this means appending elements in front of a list, making point ptr to the first element of the former list?
random question: what's the point of the having a different operator? is it to show if the structure in question is a pointer? or is there some other reason?
Its partly because it allows for sometimes having both. The -> operator can be overloaded, hence you can get things like std::unique_ptr which can be used like this:
1
2
3
4
struct A { int a };
std::unique_ptr<A> ptr { new A };
ptr->a = 5;
ptr.reset(new A);
Last edited on
Topic archived. No new replies allowed.