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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -