gpt4 book ai didi

C++ : initialize static member large array

转载 作者:可可西里 更新时间:2023-11-01 17:17:33 25 4
gpt4 key购买 nike

为了在 C++ 中使用静态数据成员,我目前有类似的东西:

// HEADER FILE .h
class MyClass {
private :
static double myvariable;
};

// CPP FILE .cpp
double MyClass::myvariable = 0;

但如果现在我有:

// HEADER FILE .h
class MyClass {
private :
static double myarray[1000];
};

如何初始化它?

谢谢

最佳答案

和初始化普通数组一样:

double MyClass::myarray[1000] = { 1.1, 2.2, 3.3 };

缺少的元素将被设置为零。

关于C++ : initialize static member large array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7205774/

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