Why do I need to override a pure virtual function if it is provided by another base class?

The following commands will not compile:

struct A
{
    virtual void foo() = 0;
};

struct B
{
    virtual void foo() {}
};

struct C : A, B
{
    using B::foo;
};

C c;

C ++ considers an Cabstract class because it failed to directly override a pure virtual one foo. What is the reason for this? I can, of course, throw an exception out of A::fooinstead of making it pure virtual, but is there a better design template?

+4
source share

Source: https://habr.com/ru/post/1662549/


All Articles