You can do this by asserting that the generic parameter type supports the gcnew() constraint. Here's an example:
#using <mscorlib.dll>
using namespace System;
ref class A
{
public:
A() { Console::WriteLine("In Constructor()"); }
};
generic <class T>
where T : gcnew()
ref class B
{
public:
T CreateT() {
return gcnew T();
}
};
int main()
{
B<A^>^ b = gcnew B<A^>;
A^ a = b->CreateT();
}
.: tomasr | 2005-04-24 18:52:38 :.