keywords: vector, list, element, multiple template types

template define:

class templateInterface
{
    virtual bool someFunction() {return true;}
};

template <typename T>
class templateClass : public templateInterface
{
    bool someFunction() {return false;}
};

setup vector elements:

std::vector<std::unique_ptr<templateInterface>> v;

templateClass<int> *i = new templateClass<int>();    // create new object
v.push_back(std::unique_ptr<templateInterface>(i));  // put it in the vector

v.emplace_back(new templateClass<int>());   // "direct" alternative

call a virtual function on one of these elements:

v[0]->someFunction();

Reference
https://stackoverflow.com/questions/16527673/c-one-stdvector-containing-template-class-of-multiple-types


愿余生有人鲜衣怒马,陪你看烈焰繁花 ;
愿余生有人素面白纱,陪你度恬淡年华 。