2017-06-26 32 views
1

我想初始化值2 d矢量,它給了我這個錯誤:無法列出初始化向量與Microsoft Visual Studio 2012

IntelliSense: initialization with '{...}' is not allowed for object of type "std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>" 

使用以下時,我會得到什麼上述錯誤?

vector<vector<int>> A = 
    { { 0, 0, 0, 0, 0, 0 }, 
     { 0, 1, 2, 2, 4, 1 }, 
     { 0, 3, 4, 1, 5, 2 }, 
     { 0, 2, 3, 3, 2, 4 }, 
     { 0, 4, 1, 5, 4, 6 }, 
     { 0, 6, 3, 2, 1, 3 } }; 
+0

注意:intellisense是* not *編譯器。 –

+2

編譯支持C++ 11或更高版本。 – DeiDei

+0

[Works just fine here](http://ideone.com/w6ySy3),你錯過了'std ::'命名空間限定符? –

回答

5

MSVS 2012 has very little C++11 support如果我們看一下鏈接到MSDN文章

enter image description here

,我們會看到,它不支持其要求與您所使用的初始化初始化列表。

我的建議是如果可以的話,升級你的編譯器。 MSVS 2017擁有最完整的C++ 11支持(禁止對新標準進行任何突破性更改)。如果你不能這樣做,那麼你可以使用pre-C++ 11的解決方案來聲明臨時數組並初始化臨時數組中的向量。

+0

@ user4581301是的。固定 – NathanOliver

相關問題