Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
What's going on is that the compiler is deciding on what function to call at compile time rather than runtime. Since the type of vh is Vehicle *, it is essentially creating this call: vh->Vehic...
Answer
#1: Initial revision
What's going on is that the compiler is deciding on what function to call at compile time rather than runtime. Since the type of `vh` is `Vehicle *`, it is essentially creating this call: ```cpp vh->Vehicle::print(); ``` There are a couple of different solutions to this, but the simplest is probably just to make the function [virtual](https://en.cppreference.com/w/cpp/language/virtual). This says that the function should be determined at runtime instead. (This is usually accomplished through virtual tables.) ```cpp class Vehicle { public: virtual void print(void) { std::cout << "this is a vehicle\n"; } }; class Car: public Vehicle { public: void print(void) override { std::cout << "this is a car\n"; } }; class Boat: public Vehicle { public: void print(void) override { std::cout << "this is a boat\n"; } }; ```