【发布时间】:2017-01-06 16:30:11
【问题描述】:
如何创建 NxM 2D int 向量并为其创建默认值?
这里我尝试用一些值创建一个 3x3 int 向量:
vector< vector<int> > m(3, vector<int> (3)) = {
{1,2,9},
{8,4,7},
{5,6,0}
};
但是这个错误与
> g++ a.cpp -std=c++11
error: expected ‘,’ or ‘;’ before ‘=’ token
vector< vector<int> > m(3, vector<int> (3)) = {
^
error: expected ‘}’ at end of input
}
我也在使用 c++11,所以上面的语法不应该是正确的吗?按照this answer的说法应该没问题吧?
【问题讨论】:
-
投票结束是一个错字。摆脱构造函数调用,因为初始化列表取代了它。
vector< vector<int> > m = ...