c++ - Why does dereferencing a string vector iterator need parentheses? -


vector<string> mystrings; vector<string>::iterator itstr; 

i'm using c_str() return pointer string.

why need dereferenced parentheses?

doesn't compile: *itstr.c_str();

error c2039: 'c_str' : not member of 'std::vector<_ty>::iterator'

compiles/works parentheses around iterator: (*itstr).c_str();

if point me (no pun intended) in right direction appreciate it.thanks!

. has higher precedence unary *.

*itstr.c_str() if had said *(itstr.c_str()).

you can, of course, use itstr->c_str(), since (*x).y equivalent x->y (at least pointers , iterators; can, of course, overload operators own types such not consistent, you'd crazy so).


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -