0

i'm trying to create a callback function in Cocos2d-X. I have a singleton class (AdsMgr). In the AdsMgr, i want to store the function pointer. How should i replace the callBackPauseResume with the passing in parameter?

AdsMgr.h

class AdsMgr
{
private:
    static bool isAdsEnabled();

public:
    static void(*callBackPauseResume)(int index);
    static void initAds(void(*incallback)(int index));
}

AdsMgr.mm

void AdsMgr::initAds(void(*incallback)(int index))
{
    callBackPauseResume = incallback;

//    incallback(1);
}

MainScene.cpp

if(btn4 && btn4->getBoundingBox().containsPoint(location))
{            
     CCLOG("SHOW INTERSTITIAL");
     AdsMgr::initAds(MainScene::pauseResumeDuringAds);
}

void MainScene::pauseResumeDuringAds(int inFlag)
{
    switch (inFlag) {
        case 0:
        // Pause game
            break;
        case 1:
            // Resume Game
            break;
        default:
            break;
    }
}

I'm unable to compile and encountered the following errors:

Undefined symbols for architecture arm64:
  "AdsMgr::callBackPauseResume", referenced from:
      AdsMgr::initAds(void (*)(int)) in AdsMgr.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
5
  • I don't understand what you're asking, can you elaborate? Specifically, I can't make any sense out of your last sentence. Commented Apr 21, 2015 at 2:51
  • I'm trying to callBackPauseResume with the passing in incallback so in my other method, i'm able to call the MainScene::pauseResumeDuringAds function. Trying to make incallback as global Commented Apr 21, 2015 at 2:55
  • Okay, so what's the problem you're experiencing? Commented Apr 21, 2015 at 3:04
  • Undefined symbols for architecture arm64: "AdsMgr::callBackPauseResume", referenced from: AdsMgr::initAds(void (*)(int)) in AdsMgr.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Commented Apr 21, 2015 at 3:05
  • Please paste it to your post. It's an essential part of the question. Commented Apr 21, 2015 at 3:05

1 Answer 1

1

Judging by your compile error, you haven't defined your callBackPauseResume variable. That's what the error is saying.

In addition to its declaration inside the class, you also need to add a definition for it, outside the class, in AdsMgr.mm:

void (*AdsMgr::callBackPauseResume)(int) = nullptr;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.