c++ - 错误 : expected unqualified-id before 'not' token g c++ builder

标签 c++ cygwin

我在程序中有一个通知类,我在这个项目的其他类中使用它。当我在 Visual Studio 2010 中运行时没问题。但是当使用 Cygwin 构建时会出现此错误“错误:在‘非’ token 之前预期不合格的 ID” 这是我的类(class)文件 .h

#ifndef __TOAST_H__
#define __TOAST_H__

#include "cocos2d.h"
#include "cocos-ext.h"
USING_NS_CC_EXT;
USING_NS_CC;

#define LOADING 1

class notificationTOAST: public CCLayer{
public:
    notificationTOAST(char* bg, char* txt, float y, float duringTime, CCObject* target);
    notificationTOAST(char* bg, char* txt, float y, float duringTime, CCObject* target,char* imgLoading);
    notificationTOAST(char* bg, char* txt, float duringTime, CCObject* target);
    notificationTOAST(char* bg, char* txt, float x, float y, float duringTime, CCObject* target);
    notificationTOAST(char* bg, char* txt,float x, float y, float duringTime, CCObject* target,char* imgLoading);
    void end();
    virtual void loop(float id);
private:
    float duringTime;
    CCObject* target;
};

#endif

文件.cpp

#include "Toast.h"
#include "Constant.h"

notificationTOAST::notificationTOAST(char* bg, char* txt, float y, float duringTime, CCObject* target){
this->target = target;
CCLabelTTF *text = CCLabelTTF::create(txt, font_arial, 20);

text->setPosition(ccp(SCREEN_W/2, y));
addChild(text,1);
CCScale9Sprite* background = CCScale9Sprite::create(bg);
background->setContentSize(CCSizeMake(text->getContentSize().width + 40, text->getContentSize().height +20));
background->setPosition(ccp(SCREEN_W/2, y));
addChild(background);
this->duringTime = duringTime;
if(duringTime > 0){
    schedule(schedule_selector(notificationTOAST::loop));
}
this->runAction(CCFadeIn::create(0.3f));
this->autorelease();
}
notificationTOAST::notificationTOAST(char* bg, char* txt, float x, float y, float duringTime, CCObject* target){
this->target = target;
CCLabelTTF *text = CCLabelTTF::create(txt, font_arial, 20);

text->setPosition(ccp(x, y));
addChild(text,1);
CCScale9Sprite* background = CCScale9Sprite::create(bg);
background->setContentSize(CCSizeMake(text->getContentSize().width + 40, text->getContentSize().height +20));
background->setPosition(ccp(x, y));
addChild(background);
this->duringTime = duringTime;
if(duringTime > 0){
    schedule(schedule_selector(notificationTOAST::loop));
}
this->runAction(CCFadeIn::create(0.3f));
this->autorelease();
}
notificationTOAST::notificationTOAST(char* bg, char* txt, float y, float duringTime, CCObject* target,char* imgLoading){
this->target = target;
CCLabelTTF *text = CCLabelTTF::create(txt, font_arial, 20);
CCSprite* loading = CCSprite::create("progress.png");
int w = text->getContentSize().width + loading->getContentSize().width + 5;
int h = loading->getContentSize().height;

loading->setPosition(ccp(SCREEN_W/2 - w/2 + loading->getContentSize().width/2,y));
CCActionInterval* rotage = CCRotateBy::create(2.0f, 360);
loading->runAction(CCRepeatForever::create(rotage));
addChild(loading,1,LOADING);
text->setPosition(ccp(SCREEN_W/2 - w/2 + loading->getContentSize().width + text->getContentSize().width/2 + 5, y));
addChild(text,1);

CCScale9Sprite* background = CCScale9Sprite::create("bgloading.png");
background->setContentSize(CCSizeMake(w + 10, h));
background->setPosition(ccp(SCREEN_W/2, y));
addChild(background);
this->duringTime = duringTime;
if(duringTime > 0){
    schedule(schedule_selector(notificationTOAST::loop));
}
this->runAction(CCFadeIn::create(0.1f));
this->autorelease();

}
notificationTOAST::notificationTOAST(char* bg, char* txt,float x, float y, float duringTime, CCObject* target,char* imgLoading){
this->target = target;
CCLabelTTF *text = CCLabelTTF::create(txt, font_arial, 20);
CCSprite* loading = CCSprite::create("progress.png");
int w = text->getContentSize().width + loading->getContentSize().width + 5;
int h = loading->getContentSize().height;

loading->setPosition(ccp(SCREEN_W*2/3 - w/2 + loading->getContentSize().width/2,y));
CCActionInterval* rotage = CCRotateBy::create(2.0f, 360);
loading->runAction(CCRepeatForever::create(rotage));
addChild(loading,1,LOADING);
text->setPosition(ccp(SCREEN_W*2/3 - w/2 + loading->getContentSize().width + text->getContentSize().width/2 + 5, y));
addChild(text,1);

CCScale9Sprite* background = CCScale9Sprite::create("bgloading.png");
background->setContentSize(CCSizeMake(w + 10, h));
background->setPosition(ccp(SCREEN_W*2/3, y));
addChild(background);
this->duringTime = duringTime;
if(duringTime > 0){
    schedule(schedule_selector(notificationTOAST::loop));
}
this->runAction(CCFadeIn::create(0.1f));
this->autorelease();

}

notificationTOAST::notificationTOAST(char* bg, char* txt, float duringTime, CCObject* target){
this->target = target;
CCLabelTTF *text = CCLabelTTF::create(txt, font_arial, 20);

CCScale9Sprite* background = CCScale9Sprite::create(bg);
background->setPosition(ccp(SCREEN_W/2,SCREEN_H- background->getContentSize().height/2));
addChild(background);

int w = background->getContentSize().width;
int h = background->getContentSize().height;

text->setPosition(ccp(SCREEN_W + text->getContentSize().width/2, SCREEN_H-h/2));
addChild(text,1);
CCFiniteTimeAction* seq = CCSequence::create(CCMoveBy::create(20,CCPointMake(-(SCREEN_W + text->getContentSize().width + 50),0)), 
                                     CCMoveTo::create(0,CCPointMake(SCREEN_W + text->getContentSize().width/2, SCREEN_H-h/2)),
                                     NULL);
text->runAction(CCRepeatForever::create((CCActionInterval*)seq));




this->duringTime = duringTime;
if(duringTime > 0){
    schedule(schedule_selector(notificationTOAST::loop));
}

this->autorelease();

}

void notificationTOAST::loop(float id){

if(duringTime == -1) return;
duringTime -= id;
if(duringTime <= 0){
    duringTime = 10;

    //this->stopAllActions();
    CCLayer* aLayer = (CCLayer*) target;
    aLayer->removeChild(this);
}

}

void notificationTOAST::end(){
CCLayer* aLayer = (CCLayer*) target;
aLayer->removeChild(this);
}

我在其他函数中调用它如下:

notificationTOAST *not = new notificationTOAST("","Loading...",SCREEN_W/2  ,SCREEN_H/2+50,3,GameController::getInstance(),"");
    not->setTag(100);
    GameController::getInstance()->addChild(not);`

最佳答案

not 是 C++ 中的关键字(! 的别名)。将您的变量重命名为其他名称。

关于c++ - 错误 : expected unqualified-id before 'not' token g c++ builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17207413/

相关文章:

c++ - 用 C++ lambda 模仿 Obj-C block 行为

cygwin - 使用 gradle 运行 grunt

C++ boost元组序列化/反序列化

c++ - 如何在totalview中查看源代码?

c++ - 重载运算符 () vs 成员函数 get()

windows - 无法在 Cygwin 中将 shell 脚本作为 KornShell 脚本执行

c 内联汇编将寄存器值加载到 esp 寄存器

windows - 如何使 yuicompressor jar 文件成为单例文件或全局可访问文件?

cygwin 上使用 FD_SET() 和消息队列进行核心转储

c++ - C++ 中的 "Y does not name a type"错误