这是我的标题:
class L {
public:
L(wstring);
~L();
private:
wstring ipath;
std::unique_ptr<freeling::tokenizer> tokenizer;
};这是我的课:
L::L(wstring language) {
}
L::~L() {
}这是主要的:
std::map<std::string, L> l;
l.insert(std::make_pair("a", L(L"b")));当我编译时,我会得到一个错误的模拟列表,但最终是:
/usr/include/c++/6/bits/stl_map.h:807:9: note: template argument deduction/substitution failed:
main.cpp:18:42: note: candidate expects 2 arguments, 1 provided
l.insert(std::make_pair("a", L(L"b")));以下是整个错误:https://pastebin.com/iU9bsBVH
奇怪的是,如果我只删除析构函数的定义和声明,代码就会编译
发布于 2017-08-17 13:03:00
您在这里发布的第一行代码中出错
std::pair<iterator,bool> insert( const value_type& value );它应该传递两个要插入的值。
例如
std::pair <std::string,double> product1; // default constructor
std::pair <std::string,double> product2 ("tomatoes",2.30); // value init
std::pair <std::string,double> product3 (product2); // copy constructor发布于 2017-08-17 13:04:37
下面的代码是编译的。
#include <map>
#include <string>
using std::string;
class LPro
{
public:
LPro(const wchar_t* _pr){ m_pr = const_cast<wchar_t*> (_pr); }
private:
wchar_t* m_pr;
};
int main()
{
std::map<string, LPro> l_pro;
l_pro.insert(std::make_pair("pt", LPro(L"pt")));
return 0;
}你是不是不小心忘了l_pro里的“L”?从编译器的注释中可以看出这一点。
https://stackoverflow.com/questions/45735397
复制相似问题