gpt4 book ai didi

C++ 在类中设置数组值

转载 作者:太空宇宙 更新时间:2023-11-04 15:51:34 25 4
gpt4 key购买 nike

我在处理看似非常简单的概念时遇到了麻烦。我有这样的类(class):

class Projectile
{
public:
int count;
int projectiles[1][3];

Projectile();
void newProjectile();

};

Projectile::Projectile()
{
count = 0;
}

void Projectile::newProjectile()
{
projectiles[0][0] = { 1, 2, 3 };
}

我试图在 projectiles 数组中设置值,我一定是做错了。我怎样才能动态地将一组值添加到该属性中?

最佳答案

projectiles[0][0]指向二维数组中的特定位置,其类型为int

如果你想动态添加项目,那么你可以使用std::vector<int> (参见 here)

关于C++ 在类中设置数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7426294/

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