我希望有一个包含向量的节点数据结构.我SIZE事先知道了向量的大小,因此我使用const说明符初始化变量.
vectorTest.cpp):#include <vector>
const int SIZE = 100;
struct node {
std::vector<int> myVec(SIZE); // ERROR: 'SIZE' is not a type
};
int main(int argc, char const *argv[]) {
std::vector<int> myVec(SIZE); // VALID
return 0;
}
Run Code Online (Sandbox Code Playgroud)
g++ 5.4.0):g++ -std=c++1y vectorTest.cpp -o vectorTest
Run Code Online (Sandbox Code Playgroud)
在里面main(),一切都很好,我可以高兴地宣布:std::vector<int> A(SIZE);.但是,当我尝试在a中定义相同的内容时struct,我会收到错误消息'SIZE' is not a type.
我知道我可以这样做来int使用C风格的数组定义来声明s 的向量,
struct other_node {
int myVec[SIZE]; // VALID
};
Run Code Online (Sandbox Code Playgroud)
但我想知道为什么这是不可能的std::vector. …