Consider the example:
#include <iostream>
class A {
public:
virtual void f();
};
void A::f()
{
std::cout << "f() from A\n";
}
class B: public A {
public:
virtual void f() = 0;
};
class C: public B {
public:
void f();
};
void C::f()
{
std::cout << "f() from C\n";
}
int main()
{
C o;
o.f();
}
A::f()
implementation is "hidden" from class C, which provides its own implementation for f()
- effectively making A::f()
more or less pointless. I see little value in such class hierarchy design, but my question whether this is a valid C++ or just "works" (such as undefined behaviours)?
A::f()
to callA
's implementation (for example :o.A::f();
). – François Andrieux Jan 23 at 15:50override
when overriding a base class'virtual
member function to avoid errors. – François Andrieux Jan 23 at 15:50A::f()
can be called directly. I just wondered if this is a valid thing. Thanks for theoverride
suggestion which I often forget! – usr Jan 23 at 16:12C::f()
could delegate part of its implementation toA::f()
again. – Daniel Schepler Jan 23 at 20:28