I do not know how to solve the problem with templates and inheritance.
My code has a template class that looks something like this:
template<typename T> class Derived : public Base{ T value; public: Derived(T arg) { value=arg; }; T getValue() { return value;}; }; class Base{ };
The only purpose of my base class is to group an array of Derived class objects. The T parameter is usually double, float, or complex, although int and struct can also be useful. (Subsequently, there should be several more similar derived classes with several additional functions.)
I can create such a group
Base** M = new Base*[numElements];
and assign them elements of a derived class, for example:
M[54] = new Derived<double>(100.);
But how can I find out that the 55th element has a value of 100 later? I need something like
virtual T getValue() = 0;
but T is the name of the derived class and may be different for any two elements of this array.
source share