first, Dae is correct, you don't want to convert the pointer returned from the Create() function into the derived class (ie, OgerMonster *m = f.Create<OGER_MONSTER>()
. If you already know the derived class type then you don't need the object factory class.
Second, I'm not sure I fully understand your problem.
Normally when you're in a situation where you want to use the object factory class, you'd create multiple instances for specific groups of classes. In other words, you don't derive every class in your game from a BaseClass type and create one BaseFactory class.
Instead you create seperate factory classes, one for each group of common classes. For example, a MonsterFactory instance for all monsters, or a RenderFactory instance for OpenGL and DirectX renderers. This way each derived class should already contain the same generic functions.
As far as accessing data that's specific to each derived class, that can be done by the class itself. For instance:
Code:
class Monster
{
public:
virtual void Execute() = 0;
};
Code:
class OgreMonster
{
private:
std::string ogre_name;
public:
void Execute() { std::cout << "Private ogre name s: " << ogre_name << std::endl; }
};
Code:
class TrollMonster
{
private:
bool is_cave_troll;
public:
void Execute() { std::cout << "Private cave troll value is: " << is_cave_troll << std::endl; }
};
If this doesn't help you, perhaps you could give me more specifics on what exactly you're trying to accomplish.
Rob Geiman