Edit

Share via


Compiler Error C3898

'var' : type data members can only be members of managed types

An initonly data member was declared in a native class. An initonly data member can only be declared in a CLR class.

The following sample generates C3898:

// C3898.cpp
// compile with: /clr
struct Y1 {
   initonly
   static int data_var = 9;   // C3898
};

Possible resolution:

// C3898b.cpp
// compile with: /clr /c
ref struct Y1 {
   initonly
   static int data_var = 9;
};