Iterating through std:list<wstring>
Pregunta
This is my code:
for (std::list<std::wstring>::iterator itr = kb->titles.begin(); itr != kb->titles.end() ; itr++)
{
_size += *itr.size();
}
What I am trying to do is access every wstring contained in the list and call it's size() member function. However what's pointed by itr does not seem to be the iterated wstring element and I'm getting an error (error C2039: 'size' : is not a member of 'std::_List_iterator<_Mylist>')
In case you are wondering what kb is it's a pointer to a struct with std::list<std::wstring> titles;
as one of it's members.
Any ideas on how to fix this?
Solución
Operator precedence is the issue here, try
_size += (*itr).size();
Or even better,
_size += itr->size();
Otros consejos
You are missing the parenthesises:
_size += (*itr).size();
_size += itr->size();
Should both work.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow