- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
考虑以下代码:
#include <unordered_map>
struct A {};
struct T
{
std::unordered_map<std::string, A> _map;
};
struct L
{
std::shared_ptr<const T> _c;
};
class f {
void oid (std::shared_ptr<L> l, std::string st, A a) {
l->_c->_map.insert(std::make_pair(st,a));
}
};
在编译过程中,它抛出以下错误:
error C2663: 'std::_Hash<_Traits>::insert' : 3 overloads have no legal conversion for 'this' pointer with [ _Traits=std::tr1::_Umap_traits,std::equal_to>,std::allocator>,false> ]
我试图删除 const
来自 std::shared_ptr<const T> _c;
(不是我认为这很重要),但它构造了一些其他错误......
感谢您的帮助!
最佳答案
您正在尝试插入 unordered_map
您已声明为 const
, 这是不允许的。为什么是_c
里面L
一个shared_ptr<const T>
???这有效地使 _map
在由共享指针管理的对象上是一个常量对象,您将无法修改它。
关于c++ - 错误 C2663 : 'std::_Hash<_Traits>::insert' : 3 overloads have no legal conversion for 'this' pointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9705803/
什么是 _hash 是随 API 请求一起收到的吗?我的请求网址, url = "https://" + sugar_instance + "/rest/v10/Leads" SugarCRM 中的每
考虑以下代码: #include struct A {}; struct T { std::unordered_map _map; }; struct L { std::shared
我是一名优秀的程序员,十分优秀!