devoured elysium
devoured elysium

Reputation: 105067

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

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?

Upvotes: 49

Views: 20433

Answers (1)

devoured elysium
devoured elysium

Reputation: 105067

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?.

Upvotes: 74

Related Questions