我试图在C++中创建双向量的结构.
struct distance{
vector<double> x(10000);
vector<double> y(10000);
vector<double> z(10000);
};
distance distance_old, distance_new;
Run Code Online (Sandbox Code Playgroud)
在定义中它抛出一个错误说:
error: expected identifier before numeric constant
error: expected ‘,’ or ‘...’ before numeric constant
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
我看到这个帖子结构的向量C++, 但它似乎并不适合我.
您正在尝试在结构中构造向量,这是无法完成的.您必须在构造函数中执行它,就像普通类一样:
struct distance
{
vector<double> x;
vector<double> y;
vector<double> z;
distance()
: x(10000), y(10000), z(10000)
{ }
};
Run Code Online (Sandbox Code Playgroud)