Creating an interface for an abstract class template in C++

前端 未结 5 564
暗喜
暗喜 2020-12-08 05:10

I have the code as below. I have a abstract template class Foo and two subclasses (Foo1 and Foo2) which derive from instantiations of the template. I wish to use pointers in

5条回答
  •  旧时难觅i
    2020-12-08 05:16

    Easiest way is to make your interface templated.

    template 
    class IFoo {
        public:
            virtual void functionA()=0;
            virtual void functionB(T arg){ do something; };
    };
    
    template
    class Foo : public IFoo{
        public:
            void functionA(){ do something; };
            void functionB(T arg){ do something; };
    };
    

提交回复
热议问题