CC_CALLBACK_1 not working... (lambda works)

CC_CALLBACK_1 not working... (lambda works)
0

Hi!

Im trying to program a menu, according to docs, i can trigger to function using macro CC_CALLBACK_1, but it is not working for me,

This is triggering an error :
MenuItemImage* notworking_item = MenuItemImage::create(BSTARTGAME_NORMAL, BSTARTGAME_PRESSED, CC_CALLBACK_1(scnMenu::onPress_StartGame), this);

This works fine:
MenuItemImage* working_item= MenuItemImage::create(BSTARTGAME_NORMAL, BSTARTGAME_PRESSED, [&](Ref* sender) { onPress_StartGame(); });

Of course i could stand for lambda way, but just curious why the first one is not working…

What may be the issue is that the signature of the lambda function is correct, whereas the signature of the scnMenu::onPress_StartGame() is not.

MenuItemImage::create(...) is expecting a function with this signature:

void(Ref* sender)

yet when you’re using CC_CALLBACK_1, you’re trying to bind a function with this signature to it:

void(void)

which I assume is what scnMenu::onPress_StartGame() is, since you haven’t shown it in your post.

CC_CALLBACK_1 is expecting a single parameter, so it should throw an error at compile time since the parameter doesn’t exist:

#define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

ok that sounds reasonable… indeed my member function had not that parameter in it…
by the way, i have used lambda for now… i will try tomorrow using Callbacks… thanks!