我的cocos2d-x代碼中存在一些問題。 我在這裏發佈我的代碼。CC_SYNTHESIZE(int,beadColor,_BeadColor);在非靜態成員函數之外無效使用'this'
BeadSprite.h
#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.cpp:31:29:無效使用的 '本' 的非靜態成員函數
以外如何解決這個錯誤?請:( 此使用的cocos2d-x-2.2.1
你期望這是指向 – Mark
這句話「‘這個’非靜態成員函數之外」是平原愚蠢 - FsetBeadColor是沒有連接到任何一個獨立的功能類(給你的編譯器一個耳光) –
@DieterLücking:We ll,'this'只在非靜態成員函數中有效,所以在該上下文之外使用'this'是一個錯誤。所以這個錯誤在技術上是正確的......它讓我想起舊的GCC未定義變量消息:「首先使用這個函數。」他們將其改進爲「首先使用此功能」,以消除「使用」一詞的歧義。 –