2010-05-17 29 views
6

我一直在尝试使用新的0X标准初始化<ints, vector<ints> >的地图,但我似乎无法获得正确的语法。我想使用带有密码的单个条目的映射:值= 1:< 3,4>在矢量地图上使用initializer_list

#include <initializer_list> 
#include <map> 
#include <vector> 
using namespace std; 

map<int, vector<int> > A = {1,{3,4}}; 

.... 

它裸片与使用gcc 4.4.3以下错误:

error: no matching function for call to std::map<int,std::vector<int,std::allocator<int> >,std::less<int>,std::allocator<std::pair<const int,std::vector<int,std::allocator<int> > > > >::map(<brace-enclosed initializer list>)

编辑

继齿轮的建议,并添加额外的支柱,现在与可摆脱了使用-fno-演绎-初始化列表标志的警告编译。这样做有没有危险?

+0

是不是你错过了大括号? – YGL 2010-05-17 20:22:55

+0

@ YGL - 修好了谢谢。尽管如此,仍然不能解决原来的问题。 – Hooked 2010-05-17 20:27:13

+0

在4.4.1上,编译器遭受精神崩溃(内部错误)。也许与4.5它工作正常? – ergosys 2010-05-17 20:33:51

回答

1

如上所述,{1,{3,4}}是地图中的单个元素,其中键为1,值为{3,4}。所以,你需要的是{ {1,{3,4}} }

简化错误:

error: no matching function for call to map<int,vector<int>>::map(<brace-enclosed initializer list>) 

不是一个精确的错误,但还是有些帮助的。