2

I have a class Notification in program and I use it in other class in this project. It ok when I run in Visual studio 2010. But when use Cygwin build occcur this error " error: expected unqualified-id before 'not' token" This my class File .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

File .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);
}

I call it in other function follow:

notificationTOAST *not = new notificationTOAST("","Loading...",SCREEN_W/2  ,SCREEN_H/2+50,3,GameController::getInstance(),"");
    not->setTag(100);
    GameController::getInstance()->addChild(not);`
idoby
  • 907
  • 8
  • 20
  • 2
    Welcome to Stackoverflow. Could you use the "edit" button and fix the formatting? You can use [Markdown syntax](http://daringfireball.net/projects/markdown/syntax). – jogojapan Jun 20 '13 at 07:14
  • `__TOAST__` is a [reserved identifier](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier). – chris Jun 20 '13 at 07:16
  • Welcome to SO! I edited your post to make it more readable, but your code is still pretty unclear. You should take a look at the changes. :) – idoby Jun 20 '13 at 07:41

2 Answers2

7

not is a keyword in C++ (an alias for !). Rename your variable to something else.

Yuushi
  • 25,132
  • 7
  • 63
  • 81
  • +1. Presumably to avoid breaking old code, Visual Studio tends to ignore this part of the Standard unless you explicitly enable it on the compiler command line, which of course just encourages writing broken/non-portable new code in VS now. – Tony Delroy Jun 20 '13 at 07:21
1

not is a C++ keyword, alias for the ! operator.

Microsoft Visual C++ is well known for not following the specification whenever Microsoft didn't feel like it. Which was whenever their existing code base didn't conform, they didn't like the specification, they had a bug and didn't feel like fixing it or any other reason. Don't rely on MSVC++ for checking any code that is supposed to be portable.

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172