如何在另一个std :: pair中插入一对std :: pair? [英] How to insert a pair of std::pair inside another std::pair?
问题描述
我要声明一个字符串到一对对的映射,如下所示:
std :: map< std :: wstring,std :: pair< std :: pair< long,long> ;,std :: pair< long,long>>参考;
我将其初始化为:
reference.insert(L"First",std :: pair< std :: pair< long,long> ;,std :: pair (std :: pair (-1,-1),std :: pair< long,long>(0,0)));
但是,Visual C ++给我错误"C2664,没有构造函数可以采用源类型,或者构造函数重载解析度不明确".
我是使用模板和STL的新手,我不知道自己在做什么错.
>>>
不能正确解析(除非您具有C ++ 0x编译器).>
更改为>>>
此:
reference.insert("First",
应该是:
reference.insert(L"First",^^^
还有一个实用函数,可以简化配对的构建:
std :: pair< std :: pair< long,long> ;, std :: pair< long,long>(std :: pair< long,long>(-1,-1),std :: pair< long,long>(0,0))
可以是:
std :: make_pair(std :: make_pair(-1L,-1L),std :: make_pair(0L,0L))
尝试一下:
reference [L"First"]= std :: make_pair(std :: make_pair(-1L,-1L),std :: make_pair(0L,0L));
I'm declaring a map of string to a pair of pairs as follow:
std::map<std::wstring,
std::pair<std::pair<long, long>,
std::pair<long, long>>> reference;
And I initialize it as:
reference.insert(L"First",
std::pair<std::pair<long, long>,
std::pair<long, long>>(std::pair<long, long>(-1, -1),
std::pair<long, long>(0, 0)));
However, Visual C++ gives me the error "C2664, No constructor could take the source type, or constructor overload resolution was ambiguous".
I'm new to using templates and STL and I can't tell what I'm doing wrong.
The >>>
can not be parsed correctly (unless you have a C++0x compiler).
Change to > > >
This:
reference.insert("First",
Should be:
reference.insert(L"First",
^^^
Also there is a utility function to make the construction of pairs easier:
std::pair<std::pair<long, long>, std::pair<long, long>>(std::pair<long, long>(-1, -1), std::pair<long, long>(0, 0))
Can be:
std::make_pair(std::make_pair(-1L,-1L),std::make_pair(0L,0L))
Try this:
reference[L"First"]
= std::make_pair(std::make_pair(-1L,-1L),std::make_pair(0L,0L));
这篇关于如何在另一个std :: pair中插入一对std :: pair?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!