我只使用C++/CLI在VS2010中單元測試非託管C++代碼。我將編譯器切換到/ clr並使用靜態庫中的非託管代碼。如何將託管引用傳遞給C++/CLI中的非託管代碼?
我在測試類中有一個簡單的int
屬性。 我想將它作爲const int &
傳遞給本機C++中的函數。但它不能編譯,我發現,這是因爲你不能混合這樣的引用。
這樣做的方法是什麼,我試圖跟隨和它的工作,但有沒有更好的方法?
[TestClass]
public ref class MyTestClass
{
private:
int _my_property;
public:
[TestMethod]
void MyTestMethod()
{
MyNativeClass c;
// c.SomeMethod(_my_property) this doesn't work
int i = _my__property;
c.SomeMethod(i) // this works
}
}
在此期間,我發現我可以使用C++風格的指針,這些指針不受管理,這對我來說已經足夠了。 'int * _my_property' – sekmet64 2011-05-21 12:15:50