Jump to

v05-l1-dynamicBinding2

In the following code, what is necessary to perform dynamic binding, i.e ptr->method() call a method from the Child class ?

class Parent {
    void method();
};
class Child : public Parent {
    // ...
};
int main() {
    Child c;
    Parent* ptr = &c;
    ptr->method();
}
  • A : redefining method in Child
  • B : declaring method as virtual in Parent
  • C : declaring method as virtual in Child
  • D : declaring method as override in Child

Answer is :

???