The conventional approach to achieve dynamic polymorphism in C++ is to define virtual functions in abstract base classes. For example
class Shape
{
public:
virtual float64 GetArea() const = 0;
virtual float64 GetPerim() const = 0;
};
Typically object instances of subclasses contain a pointer to a virtual table (vtable). A vtable is a table of pointers to implementations of the virtual functions. This allows for dynamic polymorphism because objects of different types can have different vtables and hence different implementations of the virtual functions.
For example the following call to GetArea() consults the vtable of the given object in order to call the appropriate implementation at run-time.
void WriteArea(const Shape* s)
{
std::cout << "Area = " << s->GetArea() << std::endl;
}