I am writing a generic factory class called Factory
//abstract factory
template <class C>
class Factory{
public:
virtual C* create()=0;
}
//concrete factory
template <class C>
class NormalFactory:public Factory<C>{
public:
C* create(){return new C;}
}
I want to do the following:
typedef Factory<Enemy> EnemyFactory;
EnemyFactory* e = new NormalFactory<Troll>; //Troll inherits Enemy
//client code
Enemy* enemy = e->create();
But unfortunately I can't do that since NormalFactory does not inherit Factory. Is there a way around that to accomplish what I wanted to?
(implementing an abstracted EnemyFactory without knowing the actual type of Enemy
it create()
)