1

Myclass.h の内部

Class Myclass
{
public:
Myclass();
private:
static int Myarray[12];
};

上記の静的配列を初期化する方法は?

4

2 に答える 2

7

ファイルで1回だけ定義する必要があります。.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. */

投稿されたコードは、配列の宣言にすぎません。

于 2012-07-04T07:37:06.560 に答える