在Myclass.h里面
Class Myclass
{
public:
Myclass();
private:
static int Myarray[12];
};
Run Code Online (Sandbox Code Playgroud)
如何初始化上面的静态数组?
您需要在文件中完全定义一次.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. */
Run Code Online (Sandbox Code Playgroud)
发布的代码只是数组的声明.