编译器错误 C3893
“var”:initonly 数据成员的左值只允许在类“type_name”的实例构造函数中使用
静态 initonly 数据成员只能在静态构造函数中获取其地址。
实例(非静态)initonly 数据成员只能在实例(非静态)构造函数中获取其地址。
以下示例生成 C3893:
// C3893.cpp
// compile with: /clr
ref struct Y1 {
Y1() : data_var(0) {
int% i = data_var; // OK
}
initonly int data_var;
};
int main(){
Y1^ y= gcnew Y1;
int% i = y->data_var; // C3893
}