gpt4 book ai didi

c++ - 双 vector 的结构

转载 作者:搜寻专家 更新时间:2023-10-31 01:54:48 27 4
gpt4 key购买 nike

我正在尝试在 C++ 中创建双 vector 结构。

struct distance{
vector<double> x(10000);
vector<double> y(10000);
vector<double> z(10000);
};

distance distance_old, distance_new;

在定义中它抛出一个错误说:

error: expected identifier before numeric constant
error: expected ‘,’ or ‘...’ before numeric constant

我哪里错了?

我看到了这个帖子 Structure of vectors C++但它似乎对我不起作用。

最佳答案

您正在尝试构造 结构中的 vector ,但这是无法完成的。您必须像普通类一样在构造函数中执行此操作:

struct distance
{

vector<double> x;
vector<double> y;
vector<double> z;

distance()
: x(10000), y(10000), z(10000)
{ }
};

关于c++ - 双 vector 的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9198666/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com