I got a little bit confused with the topic of virtual functions in c++. Is there a flowchart that summarize all possible cases?
for example:
class A {
public:
virtual void f(const int i) { cout << "A::f" << endl; }
};
class B : public A {
public:
// Hide A's f with new implementations
void f() { cout << "B::f" << endl; }
};
class C : public B {
public:
void f() { cout << "C::f" << endl; }
};
class D : public B { public:
void f(const int i) { cout << "D::f" << endl; }
};
void main() {
D d;
C c;
B* pb = &c;
pb->f();
A* pa = &d;
A* paa = &c;
pa->f(1);
paa->f(1); //in here C::f would be invoked?
}
In this case, B
hides A::f
, and C
has an override for B::f
with the same signature.
Would pb->f()
invoke C::f
?
Would pa->f(1)
invoke A::f
?
I ask it to know if B::f
is still considered virtual so its derivative classes can override it, though it hides A::f
.
As well as If C::f is considered virtual by default?