one way you could create the dictionary without using function pointers (I find code using function pointers to be very C-like, so personally I prefer to avoid them if there's an easy workaround) -
Code:
class ISpriteCreator //Sprite Creator interface
{
public:
virtual Sprite* Create(int int) = 0;
};
template<class ConcreteSprite>
class SpriteCreator : public ISpriteCreator
{
public:
Sprite* Create(int x, int y)
{
return new ConcreteSprite(x, y);
}
};
// .. dictionary mapping strings to sprite creators
std::map<std::string, ISpriteCreator*> dictionary;
dictionary.insert( std::make_pair( "LeftCloud", new SpriteCreator<LeftCloud> () ) );