构建我的C ++程序时,出现错误消息
未定义对'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
因此,我已经解决了这个问题,这是逻辑不良和对automake / autotools世界不完全熟悉的结合。我将正确的文件添加到我的Makefile.am模板中,但是我不确定构建过程中的哪一步实际创建了makefile本身。因此,我正在使用一个旧的makefile进行编译,而该文件对我的新文件一无所知。
感谢你的回复和指向GCC常见问题解答的链接。我一定会读到它,以避免由于真正原因而发生此问题。
简而言之:.cpp只是不包含在构建中。该错误消息确实具有误导性。
对于Qt用户:如果忘记了移动标头,则可能会遇到同样的错误。
我认为您应该接受亚历山大·哈梅兹(Alexandre Hamez)的回答。寻找此错误的人们很可能需要他的解决方案,而不是您的解决方案。
-1这可能是您的问题的解决方案,但它不是原始问题的答案。正确的答案很简单,就是您没有为目标文件提供必需的符号。为什么您未能提供他们是另一回事。
@沃尔特:实际上,这是我一直在寻找的确切答案。其他的很明显,因此无济于事。