我知道在C++/CLI中,当定义一个托管类时不能使用非托管类型:
public struct Unmanaged
{
int x;
int y;
};
public ref class Managed
{
int one;
Unmanaged two; //error C4368
};
我不明白为什么会这样。 Unmanaged
只是本地类型的集合-它的大小是已知的,那么它(我指定义它的内存块)会随着 '托管堆' 内的 Managed
的 '内存块' 一起移动,元数据中存储的任何偏移量都将保持有效,就像声明整数或浮点数一样。
为什么我们不能混合类型?