I need to store multiple types of a template class in a single vector.
Eg, for:
template
class templateClass{
bool someFunction()
Polymorphism only works through pointers or references. You'll
need the non-template base. Beyond that, you'll need to decide
where the actual objects in container will live. If they're all
static objects (with sufficient lifetime), just using
a std::vector
, and inserting with
v.push_back(&t1);
, etc., should do the trick. Otherwise,
you'll probably want to support cloning, and keep clones in the
vector: preferably with Boost pointer containers, but
std::shared_ptr
can be used as well.