I have a vector container holding pointers of a base class:
class Wrapper_base {
public:
virtual ~Wrapper_base() {}
};
template <typename T>
class Wrapper : public Wrapper_base {
private:
T t_;
public:
Wrapper(const T t) : t_(t) {}
};
Wrapper<int> a (1);
Wrapper<float> f = 2.0;
Wrapper<double> d = 3.1415;
vector<Wrapper_base*> w;
w.push_back(&a);
w.push_back(&f);
w.push_back(&d);
now, I am looking for a way to find the value wrapped by the Wrapper function. and the problem is I don't know what is the type of the derived class to down cast the base class pointer.
cout << ( (Wrapper<ReturnType?>) (w[0]) ) -> t_;
is there a way to achieve this? I don't want to check typeid value or use dynamic_cast because the design is supposed to support the general case and not a limited of number of types. I am also not looking for something like std::tuple or bost::tuple.
any suggestion?