C++: using a base class as the implementation of an interface

前端 未结 5 1087
南方客
南方客 2020-12-14 16:01

In C++ is it possible to use another base class to provide the implementation of an interface (i.e. abstract base class) in a derived class?

class Base
{
          


        
5条回答
  •  眼角桃花
    2020-12-14 16:08

    Try this:

    class Interface
    {
        virtual void myfunction() = 0;
    }
    class Base : public Interface
    {
        virtual void myfunction() {/*...*/};
    }
    class Derived
        : public Base
    {
        // myfunction is implemented by base
    }
    

提交回复
热议问题