I'm wondering if you can have a container with objects with varying template parameters.
I'm trying to achieve something like this:
#include <iostream>
#include <list>
template <class T>
class base
{
public:
T val;
base(T newVal): val(newVal) {};
};
class derived : public base<int>
{
public:
derived(int newVal): base(newVal) {};
};
int main ( void )
{
std::list < base<?> > base_collection;
return 0;
}
I want my current project to be as flexible and dynamic as possible, with little extra coding when a new derived class is necessary, and my current implementation makes it important that such a list exists.
Is there a commonly used, benefiting and clean way of achieving exactly this?
Aucun commentaire:
Enregistrer un commentaire