kingBook

导航

cocos2d-x 那些常犯的错误

Label::_label;
if(_label==NULL){
//初始化_label的代码
}
//指针默认值不等于NULL,需要赋初始值Label::_label=NULL;
string str="name is lao wang";
cocos2d::log(str);//这是错误的
cocos2d::log("%s",str);//这是错误的

cocos2d::log(str.c_str());//这才能正确输出
cocos2d::log("%s",str.c_str());//这才能正确输出

 

std::string str="ab"+"cd";//这是错误的

//正确写法
std::string str="ab";
str+="cd";
log(str.c_str());//输出:abcd

 

posted on 2016-05-26 10:27  kingBook  阅读(148)  评论(0编辑  收藏  举报