Is it possible to add a template class inside std::array without specifying the typename? I mean.
template<typename T>
class MyClass
{
...
}
std::array<MyClass *> arr;
The reason is that I have a kind of storage that accepts all classes that derives from MyClass but the problem with the template class is that I need to specify the typename, then the class need to be like that:
class Storage
{
...
private:
std::array<MyClass<TYPE GOES HERE> *> arr;
}
And I want something more or less like this:
class Storage
{
...
private:
std::array<MyClass *> arr;
}
This way I can add any class that derives from MyClass.
Is there a way for doing that?
Storagea template class as well.MyClass<int>andMyClass<double>are completely unrelated types. If you want an array that can store pointers to both, give them a common base class or use type erasure.MyBaseClassand deriveMyClassfrom it so thatStoragewill holdstd::array<MyBaseClass *> arr;. If you need to callT-specific functions ofMyClassfromStorage- then you can't do this, and basically can't makeStorageclass non-T-specific.