簡體   English   中英

將C ++字符串傳遞給ac#函數

[英]Passing C++ string to a c# function

我將Microsoft的assert類包裝在c#中,並希望在c ++中使用該代碼。 我不得不處理信息字符串的問題,我不太確定如何將c ++字符串傳遞給ac#方法。 兩者都被管理。

//c# Assert wrapper
static public bool AreEqual<T>(T expected, T actual, string info){
    //...
    WriteLine(info);
    //...
}

從c ++調用

//c++
void someCppFunc(){
    long expected = 2;
    long actual = 2;
    Assert::AreEqual<long>(expected, actual, L"Some info message");
}

但是我得到的錯誤說它沒有匹配功能。 我將如何處理?

只需傳遞一個托管字符串,而不是本地C ++字符串即可:

//c++/clr
void someCppFunc(){
    long expected = 2;
    long actual = 2;
    Assert::AreEqual<long>(expected, actual, gcnew System::String(L"Some info message"));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM