[英]Call c# from c++: how to pass nullptr to DateTime?
在ac#assembly中,我得到了一個以可以為空的DateTime作為參數的函數:
public void DoSomething(DateTime? timestamp);
現在我想從c ++ / cli調用這個方法:
MyClass->DoSomething(nullptr);
這不會編譯。 相反,c ++編譯器將打印錯誤消息,nullptr無法轉換為System :: Nullable。
那么如何將nullptr從c ++傳遞給可以為空的DateTime呢?
MyClass->DoSomething(Nullable<DateTime>());
Nullable
是一種值類型 ,C ++ / CLI不為它提供編譯時魔術。 你需要走明確路線:
System::Nullable<System::DateTime> dtnull;
MyClass->DoSomething(dtnull);
當然,你也可以在這里使用臨時的:
MyClass->DoSomething(System::Nullable<System::DateTime>());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.