map<string,string> x;
string a="abc",b="def";
x.insert(make_pair(a,b)); //正常
x.insert(make_pair("zhang","jie")); //出错
x.insert(make_pair(string("zhang"),string("jie"))); //正常
很好奇为什么第二种不行,改成第三种就可以了
string a="abc",b="def";
x.insert(make_pair(a,b)); //正常
x.insert(make_pair("zhang","jie")); //出错
x.insert(make_pair(string("zhang"),string("jie"))); //正常
很好奇为什么第二种不行,改成第三种就可以了
const value_type& _Val
);_Val
The value of an element to be inserted into the map unless the map already contains that element or, more generally, an element whose key is equivalently ordered.
make_pair(string("zhang"),string("jie"))后,VC帮你转化为STRING会帮你分配空间,就有了地址,可以转换了。
就像 &4 是错误的, 但int a = 4; &a 是对的。
个人愚见,见笑了,有错误请指出。
不知道我的理解对不对 还是应该怎样理解