【发布时间】:2015-03-27 10:06:42
【问题描述】:
我对 std::vector 有一个小问题。在 main.h 我尝试制作固定大小的 int 向量
std::vector<int> foo(7);
但是 g++ 给出了这个错误:
../test/main.h:21:26: error: expected identifier before numeric constant
std::vector<int> foo(7);
../main/main.h:21:26: error: expected ',' or '...' before numeric constant
如何创建固定大小长度的私有向量变量?或者我应该简单地在构造函数中制作
for(int i=0; i<7;i++){
foo.push_back(0);
}
【问题讨论】:
-
如果您想要一个固定大小的向量,请使用 std::array 甚至是裸 C 数组。
-
在“main.h”中?那可能是错误的地方。