Can't access a map member from a pointer

Posted by fjfnaranjo on Stack Overflow See other posts from Stack Overflow or by fjfnaranjo
Published on 2010-03-26T12:25:46Z Indexed on 2010/03/26 12:33 UTC
Read the original article Hit count: 478

Filed under:
|
|
|
|

Hi. That's my first question :)

I'm storing the configuration of my program in a Group->Key->Value form, like the old INIs. I'm storing the information in a pair of structures.

First one, I'm using a std::map with string+ptr for the groups info (the group name in the string key). The second std::map value is a pointer to the sencond structure, a std::list of std::maps, with the finish Key->Value pairs.

The Key->Value pairs structure is created dynamically, so the config structure is:

std::map< std::string , std::list< std::map<std::string,std::string> >* > lv1;

Well, I'm trying to implement two methods to check the existence of data in the internal config. The first one, check the existence of a group in the structure:

bool isConfigLv1(std::string);
bool ConfigManager::isConfigLv1(std::string s) {
    return !(lv1.find(s)==lv1.end());
}

The second method, is making me crazy... It check the existence for a key inside a group.

bool isConfigLv2(std::string,std::string);
bool ConfigManager::isConfigLv2(std::string s,std::string d) {
    if(!isConfigLv1(s))
        return false;
    std::map< std::string , std::list< std::map<std::string,std::string> >* >::iterator it;
    std::list< std::map<std::string,std::string> >* keyValue;
    std::list< std::map<std::string,std::string> >::iterator keyValueIt;
    it = lv1.find(s);
    keyValue = (*it).second;
    for ( keyValueIt = keyValue->begin() ; keyValueIt != keyValue->end() ; keyValueIt++ )
        if(!((*keyValueIt).second.find(d)==(*keyValueIt).second.end()))
            return true;
    return false;
}

I don't understand what is wrong. The compiler says:

ConfigManager.cpp||In member function ‘bool ConfigManager::isConfigLv2(std::string, std::string)’:|
ConfigManager.cpp|(line over return true)|error: ‘class std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >’ has no member named ‘second’|

But it has to have the second member, because it's a map iterator...

Any suggestion about what's happening?

Sorry for my English :P, and consider I'm doing it as a exercise, I know there are a lot of cool configuration managers.

© Stack Overflow or respective owner

Related posts about c++

Related posts about stdmap