Ad hoc polymorphism and heterogeneous containers with value semantics

Different alternatives It is possible. There are several alternative approaches to your problem. Each one has different advantages and drawbacks (I will explain each one): Create an interface and have a template class which implements this interface for different types. It should support cloning. Use boost::variant and visitation. Blending static and dynamic polymorphism For the … Read more

Heterogeneous containers in C++

Well generally C++ Containers are designed to hold objects of a single type using templates. If you want different types that are all derived from one type you can store a container of pointers (I guess you could also have a container of void* to anything…) e.g. std::vector<MyBaseType*>. If you want completely unrelated types, you … Read more