// Example of C++'s rules for method calls when extending a base class. #include using namespace std; /** This C++ class is going to be the parent class. ** It defines a toString member function. **/ class Parent { public: Parent() {}; char* toString() { return "I'm Parent's toString()"; } }; /** C++ class that inherits from Parent, also defining ** a toString() member function. **/ class Derived : public Parent { public: Derived() {}; char* toString() { return "I'm Derived's toString()"; } }; /** Test driver */ main() { Derived d; cout << d.toString() << endl; // Get at parent class's behavoir Parent p = (Parent) d; cout << p.toString() << endl; getchar(); // And, of course, there is no Object that everything // derives from in C++ so there are no other // possibilities. }