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

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -