Oussama Ben Ghorbel
Oussama Ben Ghorbel

Reputation: 2129

base operand of -> has no pointer of has non-pointer type ’

I have a map "languages" and an iterator to that map "it".

map < string, pair< pair<string,string>, pair<int,int> > > languages;
map < string, pair< pair<string,string>, pair<int,int> > >::iterator it;

I'm trying to find the pair of int to a certain element, suppose c is a string already there in the keys of my map.

Using languages.find(c)->second->second->first; I expect to get the right iterator pointing to the right element of map although I'm stuck with an error while compiling has non-pointer type std::pair<std::pair<std::basic_string<char>, std::basic_string<char> >, std::pair<int, int> >

How to fix this? Any help would be appreciated, any help with explanation would be VERY much appreciated.

Upvotes: 0

Views: 1043

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409482

While languages.find(c) returns an iterator (and you do know that element exists? Dereferencing the end iterator is UB) and therefore have an overloaded -> operator, the second member of the pair is in turn a pair and not an iterator which means you need to use the .:

languages.find(c)->second.second.first

Upvotes: 3

Related Questions