编译器错误 C3272

“symbol”:符号需要 FieldOffset,因为它是用 StructLayout(LayoutKind::Explicit) 定义的 typename 类型的成员

StructLayout(LayoutKind::Explicit) 有效时,必须用 FieldOffset来标记字段。

下面的示例生成 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_;
};