質問

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?

役に立ちましたか?

解決

Operator precedence is the issue here, try

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

Or even better,

_size += itr->size();

他のヒント

You are missing the parenthesises:

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

Should both work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top