Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Undefined reference to vtable

When creating my C++ program, I'm getting the error message
undefined reference to 'vtable...

What is the reason for this issue? How would I fix it?

My code:
class CGameModule : public CDasherModule {
public:
CGameModule(Dasher::CEventHandler pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface, ModuleID_t iID, const char *szName)
: CDasherModule(pEventHandler, pSettingsStore, iID, 0, szName)
{
g_pLogger->Log("Inside game module constructor");
m_pInterface = pInterface;
}

virtual ~CGameModule() {};

std::string GetTypedTarget();

std::string GetUntypedTarget();

bool DecorateView(CDasherView *pView) {
//g_pLogger->Log("Decorating the view");
return false;
}

void SetDasherModel(CDasherModel *pModel) { m_pModel = pModel; }


virtual void HandleEvent(Dasher::CEvent *pEvent);

private:



CDasherNode *pLastTypedNode;


CDasherNode *pNextTargetNode;


std::string m_sTargetString;


size_t m_stCurrentStringPos;


CDasherModel *m_pModel;


CDasherInterfaceBase *m_pInterface;
};


Inherits from...
*class CDasherModule;
typedef std::vector<CDasherModule*>::size_type ModuleID_t;

/// \ingroup Core
/// @{
class CDasherModule : public Dasher::CDasherComponent {
public:
CDasherModule(Dasher::CEventHandler * pEventHandler, CSettingsStore * pSettingsStore, ModuleID_t iID, int iType, const char *szName);

virtual ModuleID_t GetID();
virtual void SetID(ModuleID_t);
virtual int GetType();
virtual const char *GetName();

virtual bool GetSettings(SModuleSettings
pSettings, int *iCount) {
return false;
};

private:
ModuleID_t m_iID;
int m_iType;
const char *m_szName;
};


Which inherits from....
namespace Dasher {
class CEvent;
class CEventHandler;
class CDasherComponent;
};

/// \ingroup Core
/// @{
class Dasher::CDasherComponent {
public:
CDasherComponent(Dasher::CEventHandler* pEventHandler, CSettingsStore* pSettingsStore);
virtual ~CDasherComponent();

void InsertEvent(Dasher::CEvent * pEvent);
virtual void HandleEvent(Dasher::CEvent * pEvent) {};

bool GetBoolParameter(int iParameter) const;
void SetBoolParameter(int iParameter, bool bValue) const;

long GetLongParameter(int iParameter) const;
void SetLongParameter(int iParameter, long lValue) const;

std::string GetStringParameter(int iParameter) const;
void SetStringParameter(int iParameter, const std::string & sValue) const;

ParameterType GetParameterType(int iParameter) const;
std::string GetParameterName(int iParameter) const;

protected:
Dasher::CEventHandler *m_pEventHandler;
CSettingsStore *m_pSettingsStore;
};
/// @}


#endif
by

2 Answers

rahul07
The solution is to ensure that all virtual methods that are not pure are defined. Note that a destructor must be defined even if it is declared pure-virtual [class.dtor]/7.

Therefore, you need to provide a definition for the virtual destructor:

virtual ~CDasherModule()
{ }
pankajshivnani123
For what it is worth, forgetting a body on a virtual destructor generates the following:

undefined reference to `vtable for CYourClass'.

I am adding a note because the error message is deceptive. (This was with gcc version 4.6.3.)

Login / Signup to Answer the Question.