How to instantiate a generic base class in derived class in C++/CLI?

╄→尐↘猪︶ㄣ 提交于 2020-05-15 08:38:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!