Search code examples
c++cyclic-dependency

Not a class, namespace or enumeration?


My teacher got me a code to study and I can't figure out when I typedef the map (as i commented in the code) it works fine but when I define without typedef it doesn't seems to work. If someone could be kind to explain I would be grateful! I read something about "cyclic dependency" but not sure if it's the case here.

int main (){

    map <string, string> ri; // typedef map<string, string> maps;
    //maps ri;
    ri.insert(pair<string, string>{"Smoljan", "Dragan"});
    ri.insert(pair<string, string>{"Smolver", "Tina"});
    ri.insert(pair<string, string>{"Mirkovic", "Sonja"});

    string in;
    cout<<"Input:";
    cin>>in;

    string high(in);
    high.back()++;

    auto low = ri.lower_bound(in);

    /*(maps)*/ ri::key_compare comp;  //<----- here is the error

    //....
}

Solution

  • Well, cause is clear: ri is not a class, namespace or enumeration. It is an object.

    What you need is to place before semicolons what you put with typedef: type name.

    map <string, string>::key_compare comp; 
    

    or (C++11)

    decltype(ri)::key_compare comp;