问题
I am new to generics. My derived class need to pass the generic type to base class. My derived class itself doesn't need generic type.
class A { public: };
generic < typename T>
public ref class Base
{
public:
T m_Instance;
void Hello()
{
cout << "Base::Hello() called" << endl;
}
T GetInstance()
{
return m_Instance;
}
};
public ref class Derived : Base <A>
{
public:
void Print()
{
cout << "Derived::Print called" << endl;
Hello();
}
};
As you can you can see, my derived case knows what's the generic type for base class but I I don't know how can it derive from it and proving the type?
The application look like this and as you can see the Derived class itself doesn't use a generic type externally.
int main(cli::array<System::String ^> ^args)
{
Derived d;
d.Print();
}
来源:https://stackoverflow.com/questions/61435054/how-to-instantiate-a-generic-base-class-in-derived-class-in-c-cli