How to override a function in another base class?

前端 未结 2 1853
面向向阳花
面向向阳花 2021-01-12 04:27

I\'m not exactly sure the terminology to use, but here\'s my example:

class Base {
public:
    virtual void test() = 0;
};

class Mixin {
public:
    virtual         


        
2条回答
  •  天命终不由人
    2021-01-12 05:00

    You cannot have a class override an unrelated class's virtual function. There are different things you could do to work around this. You can make the mixin a template that derives (virtually) from the type argument and use it as class Example : public virtual Base, Mixin, or you can add code in the final class to dispatch to the mixing:

    void Derived::test() { Mixin::test(); }
    

提交回复
热议问题