Question: Assume I have the following 2 classes `Super` and `Deriv` where `Deriv` is a subclass of `Super`.

`Super` and `Deriv` are both templated classes. I want to create a `vector` of type `Super<?>`. Where the `?` signifies any type. Currently I have come up with this:

```
#include <iostream>
#include <vector>

template <typename T>
class Super {
public:
    T val;
    Super(T val) : val(val) {};
};

template <typename T>
class Deriv : public Super<T> {
public:
    Deriv(T val) : Super<T>(val) {};
};

int main() {
    std::vector<Super*> a;
    a.push_back(new Deriv<int>(1));
    a.push_back(new Deriv<float>(1.0f));

    std::cout << a[0]->val << std::endl;
    return 0;
}

```

Of course this does not work because `std::vector<Super*>` needs a template type like `std::vector<Super<int>*>`. However the problem with this is I can only add items to the vector of type `Super<int>*` and not `Super<float>*`.

How can I alter this code to allow me to add a `Super` type or it's derivatives to a vector which has any template type like `int`, `float`, `short` etc?

Answer: 
Not sure if this can solve your problem, but it might give you some ideas. The basic idea here is to make a super class for all kinds of `T`. For fundamental data types, wrapper classes are needed.

```
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

class SuperT {
public:
    virtual std::string AccessData() = 0;
};

class IntWraper : public SuperT {
public:
    IntWraper(int i) : val(i) { };
    virtual std::string AccessData() { return std::to_string(val); };
private:
    int val;
};

class FloatWraper : public SuperT {
public:
    FloatWraper(float f) : val(f) { };
    virtual std::string AccessData() { return std::to_string(val); };
private:
    float val;
};

class RealSuper {
public:
    virtual std::string DoSomething() = 0;
};

template <typename T>
class Super : public RealSuper {
public:
    T* wraper_val_;
    Super(T* w_val) : wraper_val_(w_val) { };
    ~Super() { if(wraper_val_) delete wraper_val_; };
    virtual std::string DoSomething() { return wraper_val_->AccessData(); }
};

template <typename T>
class Deriv : public Super<T> {
public:
    Deriv(T* w_val) : Super<T>(w_val) {};
};

int main() {
    std::vector<RealSuper*> a;
    a.push_back(new Deriv<IntWraper>(new IntWraper(1)));
    a.push_back(new Deriv<FloatWraper>(new FloatWraper(1.0f)));

    std::cout << a[0]->DoSomething() << std::endl;
    std::cout << a[1]->DoSomething() << std::endl;

    return 0;
}

```
Create a new class `RealSuper` that cache the type is a possible workaround. 

It is not perfect, but I am afraid that it can't be much better than this :-

```
class RealSuper{                                //<-- new class
    public: enum TYPE{ type_int, type_float, type_notIni };  // (yes, it is awkward)
    TYPE typee = type_notIni;
};
template <typename T>   class Super : public RealSuper { //<-- modify
    public:  T val;
    Super(T val) : val(val) {
        if( std::is_same<T, int>::value ){
            typee = type_int;
        }else if( std::is_same<T, float>::value ){
            typee = type_float;
        }
    };
};
template <typename T>  class Deriv : public Super<T> {
    public: Deriv(T val) : Super<T>(val) {};
};
int main() {
    std::vector<RealSuper*> a;
    a.push_back(new Deriv<int>(1));
    a.push_back(new Deriv<float>(1.0f));
    for(auto ele: a){
        switch( ele->typee ){
            case RealSuper::TYPE::type_int: {
                int value=static_cast<Super<int>*>(ele)->val;
                std::cout << value << std::endl; 
            };break;
            case RealSuper::TYPE::type_float :{
                float value=static_cast<Super<float>*>(ele)->val;
                std::cout << value << std::endl; 
            };break;
        }
    }
    return 0;
}

```

[live demo](http://coliru.stacked-crooked.com/a/19bf7bd4c65f898c)
-----------------------------------------------------------------

Here is another [demo](http://ideone.com/mSdipc) to show an approach using the virtual function.