C++ 错误 No matching member function for call to addtoucheventlistener

标签 c++ ios cocos2d-x cocostudio

我是 cocos2d-x 的新手。我在这一行中遇到错误:

Button* btnRegister=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnRegister"));
btnRegister->addTouchEventListener(CC_CALLBACK_0(LoginScene::GameLoginTest, this));//get error no matching member function for call to addtoucheventlistener

我不知道为什么,因为我已经在下面创建了一个构造函数 请帮忙,我应该怎么做才能解决这个问题

文件LoginScene.h

#include "cocos2d.h"
#include "cocos-ext.h"
#include "CocosGUI.h"

USING_NS_CC;
USING_NS_CC_EXT;

using namespace ui;

class LoginScene : public Scene
{
public:
    LoginScene(bool pPortrait=false);
    ~LoginScene();
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    //static cocos2d::Scene* createScene();

    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    //virtual bool init();

    virtual void onEnter();
    virtual void onExit();

    // a selector callback
    virtual void GameLogin();
    void GameLoginTest(Ref* pSender,TouchEventType type);
    //virtual void runThisTest()=0;
protected:

    Layer* m_pUILayer;
    Layout* m_pLayout;
    int authenticate();
    //int authenticate(const char* username, const char* password);
    // implement the "static create()" method manually
    //CREATE_FUNC(LoginScene);
};

文件LoginScene.cpp

#include "LoginScene.h"
#include "cocostudio/CCSSceneReader.h"
#include "cocostudio/CCSGUIReader.h"
#include "cocostudio/CCActionManagerEx.h"
#include "LoadingScene.h"
#include "MainScene.h"
#include "curl/curl.h"

LoginScene::LoginScene(bool pPortrait):m_pUILayer(NULL),m_pLayout(NULL)
{
    Scene::init();
}

LoginScene::~LoginScene()
{

}

void LoginScene::onEnter()
{
    Scene::onEnter();

    m_pUILayer=Layer::create();
    m_pUILayer->scheduleUpdate();
    this->addChild(m_pUILayer);

    m_pLayout=dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("LoginScene.json"));
    m_pUILayer->addChild(m_pLayout);

    Button* btnLogin = static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnLogin"));
    btnLogin->addTouchEventListener(CC_CALLBACK_0(LoginScene::GameLogin, this));//it's okay

    Button* btnRegister=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnRegister"));
    btnRegister->addTouchEventListener(CC_CALLBACK_0(LoginScene::GameLoginTest, this));
    //get error no matching member function for call to addtoucheventlistener

}
void LoginScene::GameLogin()
{
    auto scene=LoadingScene::createScene();
    Director::getInstance()->pushScene(scene);
}

void LoginScene::GameLoginTest(Ref* pSender,TouchEventType type)
{
    if (type==TOUCH_EVENT_ENDED)
    {
        if (authenticate()==1)
        {
            auto scene=MainScene::createScene();
            Director::getInstance()->pushScene(TransitionFade::create(2.3f, scene));
        }
    }
}

最佳答案

对于 LoginScene::GameLoginTest,也许你可以使用 CC_CALLBACK_2,像这样: btnRegister->addTouchEventListener(CC_CALLBACK_2(LoginScene::GameLoginTest, this));

关于C++ 错误 No matching member function for call to addtoucheventlistener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25321375/

相关文章:

ios - cocos2dx - 绕过 body 接触

ios - 如何在 AVFoundation 中混合/屏蔽视频?

ios - swift 。 iOS。当我再次运行应用程序时,存储在沙箱中的图片消失了

c++ - 可以复制/复制 CCLayer 吗?

c++ - 如何声明任意深度的对?

ios - 关闭另一个 View 后,UITableView 滚动内容大小不正确

ios - Cocos2dx 在不使用 plist 文件的情况下更改 Sprite 大小和纹理 uv

c++ - 交换不使用函数作为参数

c++ - SSD读取性能

c++ - C++ 中的堆栈、静态和堆