Question OOP-POLY-0016
HardWhat is the output of this code?
#include <iostream>
using namespace std;
struct A {
virtual void f() { cout << "A.f "; }
void g() { cout << "A.g"; }
};
struct B : A {
void f() override { cout << "B.f "; }
void g() { cout << "B.g"; }
};
int main() {
A* p = new B();
p->f();
p->g();
delete p;
return 0;
}
- A.
A.f B.g
- B.
B.f A.g
- C.
A.f A.g
- D.
B.f B.g
Sign up free to see the answer and a step-by-step explanation.