Hello, I want to store a vector of classes with different template arguments.
For example, let's say I have a class BaseType<T, K>, and I want to write something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
template<typename T, typename K>
class BaseType
{
// ***
}
template<typename T, typename K>
class DType : BaseType<T, K>
{
// ***
}
// ***
std::vector<BaseType> v = { };
v.push_back(DType<int, double>());
|
But, obviously, this is incorrect, because I can't store a vector of unspecified templates.
I tried to define a vector like this:
|
std::vector<BaseType<void*, void*>>
|
But then I need to use reinterpret_cast to set values to a such vector, and I need to use pointers as templates arguments of derived classes.
And another simple way to solve this problem (not to define BaseType as a template) doesn't work too, because I need a virtual method with template arguments in BaseType, and I can not define a virtual template function.
So, how can I solve this?