I have a problem with iterator. Could you explain me why this code:
vector<vector<int> >::iterator it = v.begin();
for(; it < v.end(); it++)
{
vector<int> var = *it;
sort(var.begin(), var.end() );
}
is ok and with this code:
vector<vector<int> >::iterator it = v.begin();
for(; it < v.end(); it++)
{
sort(*it.begin(), *it.end() );
}
is wrong? Compiler said that *it has no member begin, but I don;t know why.
Operator precedence.
*it.begin()is the same as*(it.begin()). You need(*it).begin()(or the equivalent expression,it->begin()).That is, you need to “call the member function
begin()of the object pointed to byit,” not “deference the result of calling the member functionbegin()onit” (ithas no member functionbegin(), which is why the compiler gives you the error message that you get).