2010-05-17 30 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>) 

不是一個精確的錯誤,但還是有些幫助的。