Rethink Polymorphism in C++
Nicolai Josuttis
To implement polymorphism and heterogeneous collections the usual approach is to use inheritance and virtual functions. However, that approach has significant flaws: * You have to use pointers and references * You have to use heap memory * You have to be careful with the lifetime of objects to avoid using destroyed objects and having memory leaks Recommended approaches for safer C++ like shared pointers cause their own problems (especially for the performance of a program).
So what is the best approach to deal with polymorphism and heterogeneous collections?
There are possible options you might not be familiar with, using: * Variadic templates * Move semantics * std::variant
This talk gives an overview about the problem and the options.

Nicolai Josuttis
Nicolai Josuttis (www.josuttis.com) is well-known in the community for his authoritative books and talks. For more than 25 years he has been a member of the C++ Standard Committee. He is the author of several worldwide best-sellers, including:
- C++23: The Complete Guide (upcoming)
- C++20: The Complete Guide
- C++17: The Complete Guide
- C++ Move Semantics: The Complete Guide
- The C++ Standard Library: A tutorial and Reference
- C++ Templates: The Complete Guide (w/ David Vandevoorde & Doug Gregor)