5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CREATE_FUNCマクロを引数付きinitに対応させた

Posted at

CREATE_FUNCマクロを少しだけ改造。
initの引数を好きに宣言できます。

それ以外はCREATE_FUNCとまったく同じ使い方です。
(できるだけ元のCREATE_FUNCのコードを使っています)

マクロ名はお好きに変えてください。

#define CREATE_FUNC_ARGS(__TYPE__) \
template<class... Args> \
static __TYPE__* create(Args&&... args) \
{ \
    __TYPE__ *pRet = new(std::nothrow) __TYPE__(); \
    if (pRet && pRet->init(std::forward<Args>(args)...)) \
    { \
        pRet->autorelease(); \
        return pRet; \
    } \
    else \
    { \
        delete pRet; \
        pRet = NULL; \
        return NULL; \
    } \
}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?