Overriding a virtual function with optional arguments
Why is it printing 23
as output; my expectation was 33
. Can anyone shed some light on this.
struct A {
virtual void f() {cout << "1";}
};
/* Private inheritance */
struct B : private A {
void f(int x = 0) {cout << "2";}
};
struct C : B {
void f(){cout << "3";}
};
int main() {
C obj;
B &ref = obj;
ref.f();
obj.f();
}
+3
source to share