Ambiguous conversion from pointer to member of derived class


#1

Hi.

Have this error message when compile project with menu_selector and same for callfunc_selector:
>Ambiguous conversion from pointer to member of derived class ‘PuzzlePlay’ to pointer to member of base class ‘cocos2d::CCObject’:
>class PuzzlePlay > class cocos2d::CCLayer> class cocos2d::CCNode > class cocos2d::CCObject
>class PuzzlePlay
> class PuzzleTileDelegate > class cocos2d::CCObject
here is part of PuzzlePlay class definition
header
<pre>
#include “cocos2d.h”
#include “PuzzleTile.h”
using namespace cocos2d;
class PuzzlePlay : public CCLayer, public PuzzleTileDelegate {
public:
virtual bool init;
void onBackTap;
};
</pre>
cpp
<pre>
#include “PuzzlePlay.h”
#include “PuzzleConstants.h”
#include “SceneManager.h”
using namespace cocos2d;
bool PuzzlePlay::init{
if){
CCMenuItem miBack = CCMenuItemImage::create); // PROBLEM IS HERE
CCLabelTTF
lblBack = CCLabelTTF::create;
lblBack
>setPosition(ccp(miBack~~>getContentSize.width/2, miBack~~>getContentSize().height/2));
miBack~~>addChild;
CCMenu *menuBack = CCMenu::create;
menuBack~~>setAnchorPoint(ccp(0, 0));
menuBack~~>setPosition.width/2 + 10, CCDirector::sharedDirector~~>getWinSize.height-miBack~~>getContentSize.height/2));
this~~>addChild(menuBack, 999);
return true;
}

return false;
}

void PuzzlePlay::onBackTap(CCObject *sender){
// some staff
}

what iam do wrong?

thanks.


#2

Alexander Shniperson wrote:

Hi.
>
Have this error message when compile project with menu_selector and same for callfunc_selector:
>Ambiguous conversion from pointer to member of derived class ‘PuzzlePlay’ to pointer to member of base class ‘cocos2d::CCObject’:
>class PuzzlePlay > class cocos2d::CCLayer> class cocos2d::CCNode > class cocos2d::CCObject
>class PuzzlePlay
> class PuzzleTileDelegate -> class cocos2d::CCObject
>
here is part of PuzzlePlay class definition
>
header
[…]
>
cpp
[…]
>
what iam do wrong?
>
thanks.

does PuzzleTileDelegate exten CCLayer or ccobject or ccnode ? if it does , it shouldn’t .


#3

Bill Xu wrote:

does PuzzleTileDelegate exten CCLayer or ccobject or ccnode ? if it does , it shouldn’t .

yes, it help thank you.

can you explain please why this error happens?


#4

is looks like if i wrote:

class PuzzlePlay : public CCLayer, public CCObject {
...
};

this error about twice declaration, right?


#5

CCLayer already inherits from CCObject.

If in your case, PuzzleTileDelegate inherits from CCLayer then you just need to use : public PuzzleTileDelegate.