Compiler Error C3272

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

For the latest documentation on Visual Studio 2017, see Compiler Error C3272 on docs.microsoft.com.

'symbol' : symbol requires FieldOffset, as it is a member of type typename defined with StructLayout(LayoutKind::Explicit)

When StructLayout Explicit is in effect, fields must be marked with FieldOffset.

The following sample generates C3272:

// C3272_2.cpp  
// compile with: /clr /c  
using namespace System;  
using namespace System::Runtime::InteropServices;  
  
[StructLayout(LayoutKind::Explicit)]  
ref struct X  
{  
   int data_;   // C3272  
   // try the following line instead  
   // [FieldOffset(0)] int data_;  
};  

The following sample generates C3272:

// C3272.cpp  
// compile with: /clr:oldSyntax /LD  
#using <mscorlib.dll>  
using namespace System;  
using namespace System::Runtime::InteropServices;  
  
[StructLayout(LayoutKind::Explicit)]  
__gc struct X  
{  
   int data_;   // C3272  
   // try the following line instead  
   // [FieldOffset(0)] int data_;  
};  

Show: