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
Post a Comment