When runtime polymorphism is not required, generic programming is used, as it offers non-intrusive, high performance compile-time polymorphism; examples include the C++ Standard Template Library (STL) [6], the
Only the Base class Method's declaration needs theVirtualKeyword, not the definition. If a function is declared asvirtualin the base class, it will be virtual in all its derived classes. The address of the virtual Function is placed in theVTABLEand the copiler usesVPTR(vpointer) to point ...
Disadvantages of std::variant polymorphism You need to know all the types upfront, at compile time. This forbids designs such as plugin system. It’s also hard to add new types, as that means changing the type of the variant and all the visitors. Might waste memory, as std::variant ...