Compiler Error C2814

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

'member' : a native type cannot be nested within a managed or WinRT type 'type'

A native type cannot be nested in a CLR or WinRT type. The following sample generates C2814 and shows how to fix it.

// C2814.cpp  
// compile with: /clr /c  
ref class A {  
   class B {};   // C2814  
   ref class C {};   // OK  
};  

Using Managed Extensions for C++, you must explicitly specify the "managed-ness" of an embedded type using one of the following keywords: __gc, __nogc, or __value.

The following sample generates C2814 and shows how to fix it.

// C2814_b.cpp  
// compile with: /clr:oldSyntax /c  
__gc class A {  
   class B {};   // C2814  
   __gc class C {};   // OK  
};  

Show: