Hello,
suppose i have something like this
Code:
class Storage
{
public:
Storage(int storageType)
{
switch(storageType)
{
case TYPE1:
data = new DerivedType1();
break;
case TYPE2:
data = new DerivedType2();
break;
}
}
~Storage(void)
{
delete data;
}
private:
BaseType *data;
};
What i don't like about this is that it is decided at runtime which type is allocated. Is doing this common, or is there any way to do this better? I mean i could use an enumeration for the storageType.
As i know the type at compiletime, i could use templates to specify the type, which would be a class.
What is better from a design perspective, runtime decision or using templates?
Best regards
EDIT: figured out how to pass classes as types to templates