We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.
Remove CREATE_FUNC macro, use Template
Remove CREATE_FUNC macro, use Template
Refactor #3096 [Closed]
UPDATED Constructor argument list fixed: I forget to pass argument list the object contructor.
template< typename T, typename ...Args > T * createCC( Args&& ... args ){ T * pRet = new T(std::forward(args)...); if( pRet and pRet->init() ){ pRet->autorelease(); }else if( pRet ){ delete pRet; pRet = nullptr; } return pRet; }
Redmine issue system is closed, we are using github issue system instead.
This issue was moved to https://github.com/cocos2d/cocos2d-x/issues/8245
Status: | Closed | |
---|---|---|
Start date: | 2013-10-31 | |
Priority: | Low | |
Due date: | ||
Assignee: | - | |
% Done: | 0% |
|
Category: | all | |
Target version: | - |
With c++11 it will be better to have a unique create function using templates instead of use a CREATE_FUNC macro in each class.
And then, we change from:
@ MyNewScene * scene = MyNewScene::create();@
to:
@ auto scene = cocos2d::create<MyNewScene>();@
And we remove the need for remember to add CREATE_FUN(MyNewScene); in the class.
We also can forward template parameters to allow parameters in the Object constructor: