Question

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?

Était-ce utile?

La solution

Operator precedence is the issue here, try

_size += (*itr).size();

Or even better,

_size += itr->size();

Autres conseils

You are missing the parenthesises:

_size += (*itr).size();
_size += itr->size();

Should both work.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top