0

HelloWorldScene.cpp

bool HelloWorld::init()
{
    if (!LayerColor::initWithColor(Color4B(255,255,255,255)))
    {
        return false;
    }
    auto item1 = MenuItemImage::create("btn-play-normal.png", "btn-play-selected.png", CC_CALLBACK_1(HelloWorld::doClick1, this));
    auto item2 = MenuItemImage::create("btn-highscores-normal.png", "btn-highscores-selected.png", CC_CALLBACK_1(HelloWorld::doClick2, this));
    auto item3 = MenuItemImage::create("btn-about-normal.png", "btn-about-selected.png", CC_CALLBACK_1(HelloWorld::doClick3, this));
    auto menu = Menu::create(item1, item2, item3, NULL);
    menu->alignItemsVertically();
    this->addChild(menu);
    return true;
}
void HelloWorld::doClick1(Ref* sender)
{
    log("the first menu selected");
}
void HelloWorld::doClick2(Ref* sender)
{
    log("the second menu selected");
}
void HelloWorld::doClick3(Ref* sender)
{
    log("the third menu selected");
}

HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::LayerColor
{
public:
    static cocos2d::Scene* createScene();
    virtual bool init();

    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);
    void doClick1(Ref* sender);
    void doClick2(Ref* sender);
    void doClick3(Ref* sender);
};
#endif // __HELLOWORLD_SCENE_H__

The source code in the book that I am studying is void doClick1(Object* sender); But some errors were occurred on my computer when I wrote the same code. Why Ref* makes no problem?

enter image description here

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Totally unrelated to your problem and question, but please note that all symbols starting with double underscore (like e.g. `__HELLOWORLD_SCENE_H__`) are *reserved in all scopes*. See [What are the rules about using an underscore in a C++ identifier?](https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier) for details. – Some programmer dude May 04 '19 at 15:03
  • Do not post links to images. Copy error messages and place them as text. – 273K May 04 '19 at 15:39

0 Answers0