我有一个这样定义的共享指针
typedef share_ptr<boost::unordered_map<int,string>> T;
boost::unordered_map<int,T> webData;
...
webData[100]=T(new boost::unordered_map<int,string>(make_pair(100,"json data returned")));
我总是在这个 webData
处出错线 no instance of boost::unordered_map<K,T,H,P,A>....matches the argument list
最佳答案
boost::unordered_map没有接受 std::pair 实例作为参数的构造函数。要消除错误,必须编写如下内容
#include <boost/unordered_map.hpp>
#include <boost/shared_ptr.hpp>
#include <string>
typedef boost::shared_ptr<boost::unordered_map<int, std::string> > T;
int main() {
boost::unordered_map<int, T> webData;
webData[100] = T(new boost::unordered_map<int, std::string>());
webData[100]->insert(std::make_pair(100, "json data returned"));
return 0;
}
coliru 上的相同代码是here .
关于c++ - 用作值的共享指针 - 赋值期间出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29136861/