无法将参数 1 从 int 转换为 int && 错误 [重复]

Posted

技术标签:

【中文标题】无法将参数 1 从 int 转换为 int && 错误 [重复]【英文标题】:cannot convert argument 1 from int to int && error [duplicate] 【发布时间】:2013-10-19 13:31:45 【问题描述】:

今天我想尝试将我的项目从 Visual c++ 2010 带到 Visual c++ 2013。

我在 Visual c++ 2013 中收到此错误,而我在使用 2010 版本编译时没有收到此错误。

//somewhere in the SimpleObject_list class
std::unordered_map<std::string, SimpleObject *> Object_list; 


//method which is giving me the error
void SimpleObject_list::Add(const char *Object_name, SimpleObject * Object_pointer)
    cout << "SimpleObject listed as: " << Object_name << endl;
    Object_list.insert(std::make_pair<std::string,SimpleObject *>(Object_name, Object_pointer));

错误是:

error C2664: 'std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,SimpleObject *> std::make_pair<std::string,SimpleObject*>(_Ty1 &&,_Ty2 &&)' : cannot convert argument 2 from 'SimpleObject *' to 'SimpleObject *&&'

我做错了什么?为什么我在 vc++ 2010 中没有收到任何错误?

谢谢

【问题讨论】:

【参考方案1】:

改变

Object_list.insert(std::make_pair<std::string,SimpleObject *>(Object_name, Object_pointer));

Object_list.insert(std::make_pair(Object_name, Object_pointer));

【讨论】:

要更好地描述为什么需要这样做,请看这里:***.com/questions/9641960/… @Marco 看到我的评论是在你上次评论前几秒添加的。

以上是关于无法将参数 1 从 int 转换为 int && 错误 [重复]的主要内容,如果未能解决你的问题,请参考以下文章