What is this?

Apr 8, 2014 at 7:54pm
what does this do?

 
  if(node->left)


I mean the (->)? And can this be replaced by something that does the same?
Apr 8, 2014 at 8:03pm
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 Apr 8, 2014 at 8:06pm
Apr 8, 2014 at 8:43pm
p->size();
is the same as
*p.size();
Actually it is (*p).size()
Precedence...
Apr 9, 2014 at 12:16am
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 Apr 9, 2014 at 12:20am
Topic archived. No new replies allowed.