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

mod rewrite - Using "?" when rewriting the URL -

.htaccess: Transfer name to index.php if not directory public -

Admob integration with pygame in android -