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
{
public:
    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 comment