Member function pointer error: Reference to non-static member function must be called

Member function pointer error: Reference to non-static member function must be called

this->scheduleOnce(schedule_selector(SelectGameScene::startGameCallback),this, 0.0f, false);

我收到一个错误:必须调用对非静态成员函数的引用。

void startGameCallback(float dt); //in h file

void SelectGameScene::startGameCallback(float dt)
{
    Director::getInstance()->replaceScene(TransitionFade::create(TRANSITION_TIME,     GameScene::createScene()));
}

在哪里

#define CC_SCHEDULE_SELECTOR(_SELECTOR) static_cast<cocos2d::SEL_SCHEDULE>(&_SELECTOR)
typedef void (Ref::*SEL_SCHEDULE)(float);

我在 XCode 使用 c++11 标准和 cococ2d-x ver4.0 库时遇到此错误。

更新: 我试过这段代码

this->scheduleOnce(schedule_selector(&SelectGameScene::startGameCallback),this, 0.0f, false);

我收到一个错误 Use of undeclared identifier 'schedule_selector'

Update2 我发现了问题。我通过静态方法 createScene 创建了这个 class。

class SelectGameScene : public cocos2d::Layer
{
 public:
   static cocos2d::Scene* createScene();
 }

语法 SelectGameScene::startGameCallback 无效。它必须有 &:

this->scheduleOnce(schedule_selector(&SelectGameScene::startGameCallback),this, 0.0f, false);
//                                   ^---- there

XCode 编译器认为 SelectGameScene::startGameCallback 是静态方法,但它只是一个成员函数指针。所以我决定重写这个语句。

来自

this->scheduleOnce(schedule_selector(SelectGameScene::startGameCallback),0.0f);

auto funPointer = static_cast<cocos2d::SEL_SCHEDULE>(&SelectGameScene::startGameCallback);
this->scheduleOnce(funPointer, 0.0f);

因为

#define CC_SCHEDULE_SELECTOR(_SELECTOR) static_cast<cocos2d::SEL_SCHEDULE>(&_SELECTOR)