c++ - How to define generic templated create function for subclass -
i working on cocos2dx game each subclass/scene need define something(macro) createcocos2dscene(customscenenamescreen);` following definition
#define createcocos2dscene(t)\ \ static cocos2d::ccscene * scene()\ {cocos2d::ccscene * scene = new cocos2d::ccscene; scene->init(); t * layer = new t; layer->init();scene->addchild(layer); layer->release(); scene->autorelease(); return scene;}
how can avoid specifying macro on each screen?
don't use macro this, use inline template function:
template <typename t> inline static cocos2d::ccscene* scene() { cocos2d::ccscene* scene = new cocos2d::ccscene; scene->init(); t * layer = new t; layer->init(); scene->addchild(layer); layer->release(); scene->autorelease(); return scene; }
Comments
Post a Comment