【发布时间】:2009-05-27 15:47:02
【问题描述】:
我正在用托管 C++ 的 MSTest 编写一个测试,我正在尝试测试一个非托管类。具体来说,我正在尝试使用 PrivateObject 类来调用私有方法。
这是我目前的代码:
CUnmanagedType foo;
PrivateObject privateFoo = gcnew PrivateObject( foo );
CString strFromFoo = privateFoo.Invoke( "ARandomPrivateMethod" );
当我编译时,我得到一个错误,即 foo 不能转换为 System::Type^。我尝试过以下操作:
PrivateObject privateFoo = gcnew PrivateObject( (gcnew System::Type^(foo)) );
但这不起作用,因为 System::Type^ 是一种抽象类型。有什么想法吗?
我查看了这些问题,但它们使用的是预定义类型,而不是用户定义类型: How to convert a unmanaged double to a managed string? Conversion between managed and unmanaged types in C++?
【问题讨论】:
标签: c++ managed-c++