Interestingly enough the syntax makes it looks like this: T()
. It does require the addition of a copy constructor.
generic<typename T>
public ref class Class
{
public:
Class() : member(T())
{
}
Class(Class^ c)
{
member = c->member;
}
private:
T member;
};
Edit
DOH This works too (been in C# land for so long I forgot that NULL and 0 are the same thing in C++, hence no need for different value and reference type default values):
generic<typename T>
public ref class Class
{
public:
Class() : member(0)
{
}
Class(Class^ c)
{
member = c->member;
}
private:
T member;
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…