Dra*_*jan -1 c++ cyclic-dependency
我的老师给了我一个学习的代码,我无法弄清楚我何时typedef在地图上(正如我在代码中评论的那样)它工作得很好但是当我定义没有typedef它似乎不起作用.如果有人能够善意解释我会很感激!我读了一些关于"循环依赖"的内容,但不确定是否就是这种情况.
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
//....
}
Run Code Online (Sandbox Code Playgroud)
原因很清楚:ri不是类,命名空间或枚举.这是一个对象.
你需要的是在分号之前放置你使用typedef:type name.
map <string, string>::key_compare comp;
Run Code Online (Sandbox Code Playgroud)
或(C++ 11)
decltype(ri)::key_compare comp;
Run Code Online (Sandbox Code Playgroud)