共用方式為


編譯器錯誤 C2864

'member-name' :具有類別初始化表達式的靜態數據成員必須具有非揮發性 const 整數類型

備註

若要初始化 static 定義為 volatile、非const或不是整數型別的數據成員,請使用成員定義語句。 無法在宣告中初始化它們。

範例

此範例會產生 C2864:

// C2864.cpp
// compile with: /c
class B  {
private:
   int a = 3;   // OK
   static int b = 3;   // C2864
   volatile static int c = 3;   // C2864
   volatile static const int d = 3;   // C2864
   static const long long e = 3;   // OK
   static const double f = 3.33;   // C2864
};

此範例示範如何修正 C2864:

// C2864b.cpp
// compile with: /c
class C  {
private:
   int a = 3;
   static int b; // = 3; C2864
   volatile static int c; // = 3; C2864
   volatile static const int d; // = 3; C2864
   static const long long e = 3;
   static const double f; // = 3.33; C2864
};

// Initialize static volatile, non-const, or non-integral
// data members when defined, not when declared:
int C::b = 3;
volatile int C::c = 3;
volatile const int C::d = 3;
const double C::f = 3.33;