编译器错误 C3265

无法在非托管的“unmanaged construct”中声明托管的“managed construct”

不能在非托管上下文中包含托管对象。

以下示例重现 C3265:

// C3265_2.cpp
// compile with: /clr /LD
#include <vcclr.h>

ref class A { };

class B
// try the following line instead
// ref class B
{
   A ^a;   // C3265
   // or embed the managed handle using gcroot
   // try the following line instead
   // gcroot<A^> a;
};