How to use Nullable types in c++/cli?

家住魔仙堡 提交于 2019-11-30 12:26:39

问题


I have the following code, which I thought would work:

property Nullable<double> Angle {
    Nullable<double> get() {
        return nullptr;
        }
}

It doesn't. How can I do it? Does c++/CLI even support nullable types?


回答1:


OK, found it, after a lot of hassle:

to return null, just do

return Nullable<double>();

to return non-null:

return Nullable<double>(12321);

It is important to declare the return value as Nullable<double> and not Nullable<double>^, as if you do it, when using other languages as C# and vb.net, you'll see the type as ValueType instead of double?.



来源:https://stackoverflow.com/questions/1457723/how-to-use-nullable-types-in-c-cli

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!