对vtable的未定义引用 [英] Undefined reference to vtable

查看:1029
本文介绍了对vtable的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我得到了臭名昭着的可怕的参考'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(装饰视图);
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;
};继承自...



<$ p







$ p> class CDasherModule;
typedef std :: vector< CDasherModule *> :: size_type ModuleID_t;

/// \ingroup Core
/// @ {
class CDasherModule:public Dasher :: CDasherComponent {
public:
CDasherModule :: 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;
};

这继承自....

 命名空间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常见问题。我一定会阅读,以避免这个问题发生的一个真正的原因。


So, I'm getting the infamously horrible "undefined reference to 'vtable..." error for the following code (The class in question is CGameModule.) and I cannot for the life of me understand what the problem is. At first, I thought it was related to forgetting to give a virtual function a body, but as far as I understand, everything is all here. The inheritance chain is a little long, but here is the related source code. I'm not sure what other information I should provide.

Note: The constructor is where this error is happening, it'd seem.

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

解决方案

So, I've figured out the issue and it was a combination of bad logic and not being totally familiar with the automake/autotools world. I was adding the correct files to my Makefile.am template, but I wasn't sure which step in our build process actually created the makefile itself. So, I was compiling with an old makefile that had no idea about my new files whatsoever.

Thanks for the responses and the link to the GCC FAQ. I will be sure to read that to avoid this problem occurring for a real reason.

这篇关于对vtable的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆