offsetof 宏似乎在 C++/CLI 下不起作用。
这在非托管 C++ 中运行良好,但在 CLI 中引发“错误 C2275: 'Entity' :illegal use of this type as an expression”错误。
struct Property{
char* label;
PropertyTypes type;
unsigned int member_offset;
unsigned int position;
unsigned char bit_offset;
};
struct Entity{
...
bool transparent;
...
};
Property property = {"Transparent",
TYPE_BOOL,
offsetof(Entity, transparent),
0,
0}; // C2275 HERE
CLI 有替代品吗?