如何在Coco2d-x中指定CREATE_FUNC参数
How to specify argument in CREATE_FUNC in Coco2d-x
我的MessageBoxes
类在构造函数中传递了一个参数,我希望知道我如何在CREATE_FUNC()
中指定参数,在此上下文中是std::string _content
?
我得到的错误是"构造函数不能被声明为'static'"
这是MessageBoxes.h: 的代码class MessageBoxes : public cocos2d::Node
{
private:
Sprite* _sprite;
bool _speaking;
float _speakingTime;
std::string _content;
public:
CREATE_FUNC(MessageBoxes(std::string content));
protected:
virtual bool init(std::string _content);
void setSprite();
void setContent();
};
CREATE_FUNC是在CCPlatformMacros.h中定义的预定义宏
#define CREATE_FUNC(__TYPE__)
static __TYPE__* create()
{
__TYPE__ *pRet = new(std::nothrow) __TYPE__();
if (pRet && pRet->init())
{
pRet->autorelease();
return pRet;
}
else
{
delete pRet;
pRet = NULL;
return NULL;
}
}
代码
CREATE_FUNC(对话框内容(std:: string));
实际上是
new(std::nothrow) MessageBoxes(std::string content)();
在c++中有编译错误。
但是你可以自己编写类似于CREATE_FUNC的创建函数,比如
static MessageBoxes* create(std::string content) {
MessageBoxes* ret = new(std::nothrow) MessageBoxes();
if(ret && ret->init(content)) { //<----Or anything you wanna init with
ret->autorelease();
return ret;
} else {
delete ret;
ret = nullptr;
return nullptr;
}
}
相关文章:
- Using C++ CryptAPI:CNG Create CSR
- 错误:(-210:不支持的格式或格式组合)功能'create'中的硬件视频解码器不支持视频源
- 表观调用前面的表达式必须具有指向 func 类型的指针
- 不能在 if 语句 - c++ 中使用 void func 直接将字符串转换为大写
- Firebase C++VS2018 SDL2-在Firebase::app::create(..)上执行异常处理
- 在扣除自动之前使用decltype(auto) <func>
- QThread::create 似乎没有将参数传递给函数
- Understanding void func(A())
- DLL+导出类+模板成员func=未解析的外部符号.任何修复的机会
- 如何在派生类中不显式调用base::func()的情况下从基类执行虚拟函数
- 为什么"non-standard syntax; use '&' to create a pointer to member"在 CTOR 中使用线程?
- QThread::create running on UI Thread
- C++语法错误,编译器不会警告或 int v = func(&v) 出错;
- 空指针(为缺少的输出数组调用的 create() 在 create,文件 /home/m/OpenCV/modules/
- 使用宏替换工厂模式样式 API 中的"create()"函数
- 为什么 decltype(declval()<T>.func()) 可以工作,而 decltype(&T::func) 不能工作?
- 错误:'create'不是 'cv::Tracker' 的成员
- 是否可以交换在 c++ 中作为函数 func(say) 中的参数传递的 const 向量的两个元素,例如:vector<int>func (const vector<int>&
- Gtk::Main 和 Gtk::Application::create 有什么区别?
- C++,如何将返回值的函数传递给 func