Introduction to OOP | Chapter 16: Overriding : | next | previous | audio | real | text |
class Parent { public: // note, no virtual keyword here void example () { cout << "Parent" << endl; } }; class Child : public Parent { public: void example () { cout << "Child" << endl; } }; Parent * p = new Parent(); p->example() Parent Child * c = new Child(); c->example() Child p = c; // be careful here! p->example() Parent