Error:"non-virtual thunk to cocos2d::CCLayer::ccTouchBegan......

Can anyone tell me how to fix these issues? Thanks!

Undefined symbols for architecture i386:
“non-virtual thunk to cocos2d::CCLayer::ccTouchBegan(cocos2d::CCTouch**, cocos2d::CCEvent**)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::ccTouchEnded(cocos2d::CCTouch**, cocos2d::CCEvent**)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::ccTouchMoved(cocos2d::CCTouch**, cocos2d::CCEvent**)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::ccTouchesBegan(cocos2d::CCSet**, cocos2d::CCEvent**)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::ccTouchesEnded(cocos2d::CCSet**, cocos2d::CCEvent**)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::ccTouchesMoved(cocos2d::CCSet**, cocos2d::CCEvent**)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::ccTouchCancelled(cocos2d::CCTouch**, cocos2d::CCEvent**)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::ccTouchesCancelled(cocos2d::CCSet**, cocos2d::CCEvent**)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::didAccelerate(cocos2d::CCAcceleration*)”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::keyBackClicked()”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
“non-virtual thunk to cocos2d::CCLayer::keyMenuClicked()”, referenced from:
vtable for DTLoginLayer in DTLoginLayer.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Could you show your code for the DTLoginLayer.h file?

ParentLayer header
@
#ifndef ChaosWarNew_DTParentLayer_h
#define ChaosWarNew_DTParentLayer_h

#include “cocos2d.h”
#include “cocos-ext.h”

USING_NS_CC;
USING_NS_CC_EXT;

class DTParentLayer: public CCLayer
{

private:
CCSprite* m_sNewBGBorder;

//Title
CCLabelTTF* m_lblTitle;

//Gold and Diamond
CCSprite* m_pGold;
CCSprite* m_pDiamond;
CCLabelTTF* m_lblGold;
CCLabelTTF* m_lblDiamond;

//Charge
CCControlButton* m_btnCharge;

//Tab Button
CCSprite* m_pTabSel;

//Click Event
void onChargeClick(CCObject* pSender);
void onTabButtonClick(CCObject* pSender);

public:
//Help Icon
CCSprite* m_pGuideIcn;

void createGuideIcn();
void createGuideIcn(CCPoint point);
void removeGuideIcn();
void startGuideAction(CCPoint point);

DTParentLayer(void);
virtual DTParentLayer;
\ virtual\ bool\ init;
\ virtual\ void\ onEnter;
\ virtual\ void\ onExit;
\ void\ addBackground;
\ void\ addBackgroundBorder;
\ void\ addBackgroundBottomBorder;
\ void\ addBackgroundBorderBlank;
\ void\ addTitle;
\ void\ setTitle;
\ void\ addGoldAndDiamond;
\ //Gold\ and\ Diamond
\ void\ updateGoldAndDiamond;
\ void\ createTabButtons;
\ void\ setTabButtonBackgroundGray;
\ void\ setTabButtonBackgroundNormal;
\ void\ moveTabBackground;
\ //CreateCCControlBUtton
\ CCControlButton*\ createBottomButton;
\ CCControlButton*\ createAnyButton;
\ CCControlButton*\ createAnySmallButton;
\ CCControlButton*\ createAnyMainButton;
\ CCTableView*\ createHorTableView;
\ //CreateInnerPanel
\ CCSprite*\ createInnerPanel;
\ CCSprite*\ createBagPanel;
\ CREATE_FUNC;
};
#endif
@
DTLoginLayer\ header
@
ifndef\ ChaosWarNew_DTLoginLayer_h
#define\ ChaosWarNew_DTLoginLayer_h
#include\ “cocos2d.h”
#include\ “DTParentLayer.h”
#include\ “DTCursorTextField.h”
#include\ “DTGameData.h”
#include\ “DTHelpTalkView.h”
#include\ “DTAboutView.h”
USING_NS_CC;
USING_NS_CC_EXT;
class\ DTLoginLayer\ :\ public\ DTParentLayer
{
private:
\ CCArray*\ m_pRoleArray;
\ DTHelpTalkView*\ m_pFirstLoginTalk;
\ DTAboutView*\ m_pAboutView;
\ CCSprite*\ m_pProgressMid;
\ CCLabelTTF*\ m_pLblProgress;
\ CCMenuItemImage*\ btnLogin;
\ CCMenuItemImage*\ m_pBtnRole1;
\ CCMenuItemImage*\ m_pBtnRole2;
\ CCMenuItemImage*\ m_pBtnRole3;
\ CCMenuItemImage*\ m_pBtnRole4;
\ CCArray*\ m_pPhotoArray;//头像数组
\ CCArray*\ m_pNameArray;//角色名数组
\ std::string\ m_strGoodsVersion;
\ std::string\ m_strSkillVersion;
\ std::string\ m_strTaskVersion;
\ std::string\ m_strAchievementVersion;
private:
\ void\ onFirstInit;
\ void\ menuLoginClick;
\ void\ menuRegisterClick;
\ void\ menuDeleteClick;
\ void\ onRoleClick;
\ void\ onAboutClick;
\ void\ onConfirmWarning;
\ void\ onConnBreak;
\ void\ onConnected;
\ void\ onServerVersionCb;
\ void\ onServerStatusCb;
\ void\ onServerVarCb;
\ void\ onAllItemCb;
\ void\ onAllSkillCb;
\ void\ onAllSkillSetCb;
\ void\ onAllSkillPetCb;
\ void\ onAllPetConfigSkillCb;
\ void\ onAllTaskCb;
\ void\ onAllAchievementCb;
\ void\ onRequestPlayerInfo;//获取玩家信息
\ void\ onLoginCb;
\ void\ onLogin91Succeed;//91登录成功
\ void\ onIs91RegisteredCb;//是否注册过
\ void\ onLoginMuheSucceed;//Muhe登录成功
\ void\ onLoginMuheFail;//Muhe登录失败
\ void\ onRemoveAbout;
public:
\ DTLoginLayer;
\ virtual
DTLoginLayer(void);
virtual bool init();
virtual void onEnter();
virtual void onExit();

CREATE_FUNC(DTLoginLayer);
};
@

#endif

Compile time error you don’t understand?

Find a line number or start commenting out everything systematically.

Have you reimplemented functions mentioned in your error log (i.e. didAccelerate(…) or ccTouchBegan(…) ) in your source files? If so you also need to add their declaration to header files - this is different from Objective-C where you could just reimplement parent class methods without adding their declarations to header files.

Thanks everyone, problem is resolved.
Nothing wrong with my code. This error is caused by multiple Inheritance, the Inheritance order is important.

change
class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCKeypadDelegate, public CCAccelerometerDelegate
to
class CC_DLL CCLayer : public CCTouchDelegate, public CCKeypadDelegate, public CCAccelerometerDelegate, public CCNode

done!

1 Like