首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >std::地图插入,候选人需要2个参数,1个提供

std::地图插入,候选人需要2个参数,1个提供
EN

Stack Overflow用户
提问于 2017-08-17 12:39:59
回答 2查看 3K关注 0票数 0

这是我的标题:

代码语言:javascript
复制
class L {
    public:
        L(wstring);
        ~L();
    private:
        wstring ipath;
        std::unique_ptr<freeling::tokenizer> tokenizer;
};

这是我的课:

代码语言:javascript
复制
L::L(wstring language) {

}

L::~L() {

}

这是主要的:

代码语言:javascript
复制
std::map<std::string, L> l;
l.insert(std::make_pair("a", L(L"b")));

当我编译时,我会得到一个错误的模拟列表,但最终是:

代码语言:javascript
复制
/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

奇怪的是,如果我只删除析构函数的定义和声明,代码就会编译

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-17 13:03:00

您在这里发布的第一行代码中出错

代码语言:javascript
复制
std::pair<iterator,bool> insert( const value_type& value );

它应该传递两个要插入的值。

例如

代码语言:javascript
复制
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
票数 0
EN

Stack Overflow用户

发布于 2017-08-17 13:04:37

下面的代码是编译的。

代码语言:javascript
复制
#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”?从编译器的注释中可以看出这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45735397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档