Subclassing the singleton classes

Subclassing the singleton classes
0.0 0


I want to subclass a singleton class, in this case SpriteFrameCache. The way singletons are implemented in cocos2d-x right now, they can’t be easily subclassed, as far as I can tell. (So why are some data members even protected - why not private?).

One conceivable solution could be to have a new static member
SpriteFrameClassCreator *_subclassCreator
in the singleton class. In getInstance(), if the static member is set, call _subclassCreator->createSpriteFrameCache().
Otherwise, just call constructor as usual. (The pointer would be set with a new static method).

Would a solution along these lines have a chance of being accepted into cocos2d-x? In that case, I think it should be done for all the singleton classes.


Maybe submit this as a feature request?


Thanks for the suggestion!