C++ CC_合成(int,beadColor,_beadColor);无效使用';这';在非静态成员函数之外

C++ CC_合成(int,beadColor,_beadColor);无效使用';这';在非静态成员函数之外,c++,cocos2d-iphone,C++,Cocos2d Iphone,我的cocos2d-x代码中有一些问题。 我把代码贴在这里 贝德斯普林特酒店 #include "cocos2d.h" #include "iSet.h" #include "LHSprite.h" enum{ BlueBead = 1, RedBead = 2, GreenBead = 3, WhiteBead = 4, BlackBead = 5, HeartBead = 6, StrongBlueBead = 7, Stro

我的cocos2d-x代码中有一些问题。 我把代码贴在这里

贝德斯普林特酒店

#include "cocos2d.h"
#include "iSet.h"
#include "LHSprite.h"

enum{
    BlueBead = 1,
    RedBead = 2,
    GreenBead = 3,
    WhiteBead = 4,
    BlackBead = 5,
    HeartBead = 6,
    StrongBlueBead = 7,
    StrongRedBead = 8,
    StrongGreenBead = 9,
    StrongWhiteBead = 10,
    StrongBlackBead = 11,
    StrongHeartBead = 12,
    ClearBead = 13,
};

USING_NS_CC;

class BeadSprite : public LHSprite
{
private:

    void changeBeadColorAction(int ToColor);
    void changeBeadColor(int ToColor);
    void boombBeads(int ToColor);
    void boombStrongBeads(int ToColor);
    void boombStrongFX();
    void runShatterEffectWithCan(CCDelayTime* time);
public:
    /*static LHSprite* spriteWithName(const std::string& spriteName,
                                    const std::string& sheetName,
                                    const std::string& spriteHelperFile);*/
    CC_SYNTHESIZE(int, beadColor, _BeadColor);
};

#endif
BeadSprite.cpp

#include "BeadSprite.h"
using namespace cocos2d;

void FsetBeadColor(const std::string& color){
    if(color == "BlueBead") this->beadColor = BlueBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "RedBead") this->beadColor = RedBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "GreenBead") this->beadColor = GreenBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "WhiteBead") this->beadColor = WhiteBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "BlackBead") this->beadColor = BlackBead; <-Invalid use of 'this' outside of a non-static member function
    if(color == "HeartBead") this->beadColor = HeartBead; <-Invalid use of 'this' outside of a non-static member function
}

void changeBeadColorAction(int ToColor){

}
#包括“BeadSprite.h”
使用名称空间cocos2d;
void FsetBeadColor(常量标准::字符串和颜色){

如果(颜色=“蓝头”)这->beadColor=BlueBead;beadColor=RedBead;beadColor=GreenBead;beadColor=WhiteBead;beadColor=BlackBead;beadColor=HeartBead;您使用
CC\u synthesis
将创建一个私有成员
beadColor
和公共getter
获取beadColor
和setter
设置beadColor
。因此您的函数实现了上的名称错误,需要限定为属于类
BeadSprite

void BeadSprite::set_BeadColor(const std::string& color) {
  // ...
}

你期望它指向什么?短语“'this'在非静态成员函数之外”是非常愚蠢的-FsetBeadColor是一个独立函数,没有连接到任何类(给你的编译器一记耳光)@DieterLücking:嗯,
这个
只在非静态成员函数内部有效,因此在该上下文之外使用
这个
是一个错误。因此,这个错误在技术上是正确的……它让我想起了旧的GCC未定义变量消息:“首先使用这个函数”。他们将其改进为“首先在这个函数中使用”为了消除“使用”这个词的歧义,@JoeZ是的,从技术上讲,但是要记住twisting@DieterL吕克:这就是为什么我把它与GCC的旧的扭曲思维的错误相比较。最初几次我看到它时,我想“但那是一个变量,不是一个函数,我正在使用它!”然后,在接下来的几年里,我帮助同学们,我不得不向他们解释同样的事情…:-)一旦他们修复了,他们就可以删除方法中所有不必要的
this->
。我尝试删除
this->
,但这不是修复错误。@user3111438其他事情你都做了吗?