Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个指向本机类的指针,并希望将其临时包装在一个对象中。我假设 System::Reflection::Pointer::Box() 函数将是要走的路。但是我无法将第二个参数格式化为它。
class A {} A * a; Object ^ o = Box(a, A::typeid);
我收到一个运行时错误,上面写着“类型必须是指针”,我想它应该是。但我无法弄清楚语法。
我也无法开始System.Reflection.Pointer.Box工作,但我发现有能力做你想做的事情IntPtr。
System.Reflection.Pointer.Box
IntPtr
A * a = new A; Object ^o = gcnew IntPtr(a); // a is boxed in o IntPtr i = safe_cast<IntPtr>(o); // Unbox the IntPtr A * aIsBack = static_cast<A*>(i.ToPointer()); // Retrieve a