Achieve polymorphism using base class pointers and virtual functions.
Polymorphism allows objects of different classes to be treated through a common interface. In C++, this is primarily achieved at runtime through virtual functions and base class pointers or references. Here's how it works: you define a common interface in a base class using `virtual` functions. A `virtual` function is a member function that you declare in a base class and expect to redefine in derived classes. When you have a pointer or reference to the base class that actually points to an object of a derived class, calling a virtual function on that pointer/reference will execute the derived class's version of the function. This decision of which function to call is made at runtime, a process called dynamic dispatch or late binding. For example, you could have a base class `Shape` with a virtual function `draw()`. Derived classes like `Circle` and `Square` would each provide their own implementation (override) of the `draw()` function. Then, you can have an array of `Shape*` pointers, where each pointer can point to either a `Circle` object or a `Square` object. When you loop through the array and call `draw()` on each pointer, the correct `draw()` function (either `Circle`'s or `Square`'s) will be invoked automatically. This allows for writing flexible and extensible code, as you can add new shapes without changing the code that manages and draws them.