gpt4 book ai didi

c++ - 未定义的 vtable 引用

转载 作者:太空宇宙 更新时间:2023-11-04 12:54:04 25 4
gpt4 key购买 nike

在构建我的 C++ 程序时,我收到错误消息

undefined reference to 'vtable...

这个问题的原因是什么?我该如何解决?


碰巧我遇到了以下代码的错误(有问题的类是 CGameModule。)我终究无法理解问题所在。起初,我认为这与忘记给虚函数一个主体有关,但据我了解,一切都在这里。继承链有点长,但这里是相关的源代码。我不确定我应该提供哪些其他信息。

注意:构造函数是发生此错误的地方,看起来。

我的代码:

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;
};

继承自...

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;
};

继承自....

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

最佳答案

GCC FAQ上面有一个条目:

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.

因此,您需要为虚拟析构函数提供一个定义:

virtual ~CDasherModule()
{ }

关于c++ - 未定义的 vtable 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47506721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com