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