编译器错误 C3887

“var”:literal 数据成员的初始值设定项必须是常量表达式

literal 数据成员只能使用常量表达式进行初始化。

下面的示例生成 C3887:

// C3887.cpp
// compile with: /clr
ref struct Y1 {
   static int i = 9;
   literal
   int staticConst = i;   // C3887
};

可能的解决方法:

// C3887b.cpp
// compile with: /clr /c
ref struct Y1 {
   literal
   int staticConst = 9;
};