struct A {
virtual void foo() { std::cout << "a";};
};
struct B:public virtual A {
void foo() { std::cout << "b";}
};
struct C:public virtual A {
void foo() { std::cout << "c";}
};
struct D:public B, public C {
};
int main() {
return 0;
}
So this one when compiling gives us the following error:
\main.cpp:16:8: error: no unique final overrider for 'virtual void A::foo()' in 'D'
struct D:public B, public C {
If we inherited the non-virtual structures B and C, the code compiles immediately without errors (but, of course, an error occurs if we call dd.foo ()). So what's the difference? Why do we have a mistake when we inherit our class practically and without errors, if we do it directly?
source
share