What is this?

what does this do?

 
  if(node->left)


I mean the (->)? And can this be replaced by something that does the same?
closed account (EwCjE3v7)
what does this do?


It calls a member function to what a pointer or iterator is pointing at.


p->memfunc;
Where p is a pointer and memfunc is a member fuction

And can this be replaced by something that does the same?


like calling size on a pointer to a vector;

p->size();

is the same as

*p.size();

http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
http://msdn.microsoft.com/en-us/library/b930c881.aspx

Last edited on
p->size();
is the same as
*p.size();
Actually it is (*p).size()
Precedence...
Basically the way I understand it is, left is a function of the node object. Much like get() is a function of cin. However the arrow is used because node actually represents the address where the memory that was allocated to it starts.

*node represents the actual information stored there so (*node).left(); is the same thing as node->left;

I'm fairly new at C++ and could be wrong but I believe this is right.
Last edited on
Topic archived. No new replies allowed.