c++ - Iterator Dereferencing -
i using vector in c++,
vector<agents> agentlist; why work,
(agentlist.begin() )->print(); and not?
*(agentlist.begin() ).print(); isn't valid dereference iterator using *?
see operator precedence, . has higher precedence *
*(agentlist.begin()).print(); represents as:
*((agentlist.begin()).print()); while iterator has no .print() function call, compiler throw out compile error.
you need:
agentlist.begin()->print(); or (*agentlist.begin()).print();
Comments
Post a Comment