Myclass.h 内部
Class Myclass
{
public:
Myclass();
private:
static int Myarray[12];
};
如何初始化上面的静态数组?
最佳答案
您需要在 .cpp
文件中定义一次:
int MyClass::MyArray[12] = { 0, 1, 2 }; /* Definition and initialisation.
Any elements not explicity
initialised will be
value-initialised,
0 in the case of int. */
发布的代码只是数组的声明。
关于c++ - 在类中使用静态数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11324418/