Cocos2d-x错误笔记整理(5)

在Xcode中使用Cocos2d-x开发时,遇到'Out-of-line definition of ‘getBackImage’ does not match any declaration in ‘Card’'的错误。该问题源于CC_PROPERTY宏定义的get和set方法与类中声明不一致。解决方法包括将宏定义替换为常规的get和set方法,并确保访问权限正确。示例代码展示了修正后的get和set实现。
摘要由CSDN通过智能技术生成

Out-of-line definition of ‘getBackImage’ does not match any declaration in ‘Card’

背景分析:在vs中没有这个错误,在xcode中有可能会出现这个问题。
// CC_PROPERTY(Node*, _backImage, BackImage);
// CC_PROPERTY(Node*, _frontImage, FrontImage);

封装的get和set方法,有可能会报:
Out-of-line definition of ‘getBackImage’ does not match any declaration in ‘Card’

解决办法:
方法一:
将上面的方法改为普通的get和set方法:
// 将上面方法修改为普通方法
Node* _backImage;
void setBackImage(cocos2d::Node* var);
Node* getBackImage();

Node* _frontImage;
void setFrontImage(cocos2d::Node* var);
Node* getFrontImage();

可能需要注意的是他的作用区域,是protected还是public。

具体上面方法实现的代码参考如下:
Node* Card::getBackImage(){
return _frontImage;
}

Node* Card::getFrontImage(){
return _frontImage;
}

void Card::setFrontImage(cocos2d::Node* var){
if(nullptr =

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值