if I have
list<NS*> v;
typename list<NS*>::iterator it;
for(it = v.begin();it!=v.end();++it){
cout<<**it.ns_member1<<endl; // does not compile
NS ns = **it;
cout<<ns.ns_member1<<endl; // this compiles.
}
Why so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Dereference (the ‘*’) has a lower precedence than the ‘.’ operator, so this line:
Works out like this:
I would suggest doing it like this:
There is really no need to use the dereference operator twice, once followed by the ‘->’ operator will do the same thing and should read clearer to most people.
HTH.