The code was given, and it was necessary to answer what it would display:
class Base { public: virtual void someMethod() const { std::cout << "Base" << std::endl; } }; class Derived : public Base { public: void someMethod() const { std::cout << "Derived" << std::endl; } }; int main( int argc, char* argv[] ) { Derived o; Base* po = &o; Base bo = o; po->someMethod(); bo.someMethod(); return 0; } What will be displayed on the screen? I answered correctly:
Derived Base In the first case, polymorphism. We look at the object on the right and during the method call the real type of the object is determined on the right and the table of virtual functions looks. In the second case, we simply have a base class object that knows nothing about the derivative. How to explain? Does the polymorphism type work only on pointers? How to explain this moment correctly?