C++/CLI equivalent for C#’s default(T)

This question was recently asked in one of the Code Project forums. Here’s what you need to do:

generic<typename T> ref class GenericList
    T GetNext()
        T temp = T();
        return temp;

In the above code snippet T() is identical to default(T) in C#, and will generate the exact same msil.

One thought on “C++/CLI equivalent for C#’s default(T)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s