- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在构建我的 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/
我对 virtual inheritance 很感兴趣这件事给我带来了神秘感。让我们以 virtual inheritance 为例。 : struct Base { virtual void
虽然手头的问题已解决,但让我有点困惑的是什么数据用于构造类的虚表以及虚表的布局存储在哪里。如果有人可以提供澄清或指出一些可能满足我好奇心的信息,我将不胜感激。 背景 两个独立的 VC6.0 项目:一个
关于我的环境的信息 Mac OS 大苏尔:11.4 VS for Mac:8.10.6(内部版本 10) Xamarin.Android:11.3.0.4 SDK 工具版本:26.1.1 SDK平台工
根据我的理解,VTable 是调用最派生版本的函数所必需的。它将包含有关函数的最派生版本的条目......我的疑问是为什么我们需要为基类提供一个 VTable。因为使用基对象进行调用总是需要调用基类函
我读了这篇文章: https://shaharmike.com/cpp/vtable-part2/ 我不明白为什么在 vtable 中(在文章末尾)我们有这个指针: 0x400918 0x400820
#include #include using namespace std; class Foo { public: virtual void f1() { cou
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。更详细地描述您的问题或inclu
class Base { public: virtual void function1() {}; virtual void function2() {}; }; class D1:
Variant-like 类型通常通过模拟 Vtables 来实现,参见示例 https://www.youtube.com/watch?v=uii2AfiMA0o 现在,作为替代方案,我们可以简单地
假设我有一个继承自 B 类和 C 类的 A 类(多重继承)。A 类有多少 vtable 成员?单继承是什么情况? 此外,假设: Class A : Public B {} 和: B* test = n
我知道这里有很多关于 vtables 的问题,但我还是有点困惑。 只有当我们有一个指向基类的指针来解析要调用派生类的哪个虚函数时,才使用 vtables 吗? 在我下面的示例中,在第一种情况下,是否在
我有一些关于虚拟析构函数和 vtable 的具体问题。 假设我有以下代码: class Base { public: virtual ~Base(); }; class Child : pub
这个问题在这里已经有了答案: What is a vtable in C++ [duplicate] (3 个答案) Why do we need a virtual table? (5 个答案)
如何在位置无关代码中实现虚函数? 我知道如果我的类有虚函数,编译器通常会为它生成一个 vtable,其中包含所有虚函数的地址,并在我的类的每个对象中存储一个指向 vtable 的指针。 现在,如果我的
网上有很多关于虚表的资源。他们通常对他们有相同的陈述: "只要类本身包含虚函数或重写父类的虚函数,编译器就会为该类构建一个 vtable。这意味着并非所有类都有编译器为它们创建的 vtable。 vt
我对 vtables 的理解是,如果我有一个带有虚函数 speak() 的类 Cat,它有子类 Lion 和 HouseCat,则有一个 vtable 将 speak() 映射到每个子类的正确实现。于
vtable 包含指向那个类的虚函数的指针。它是否也包含指向非虚函数的指针? 谢谢! 最佳答案 这是一个实现细节,但不是。如果一个实现将指向非虚函数的指针放入虚表中,它就不能使用这些指针进行函数调用,
我们有没有virtual table对于 abstract class ? 最佳答案 首先,vtables 的使用是实现定义的,而不是标准强制要求的。 对于使用 vtable 的实现,答案是:是的,通
你能解释一下编译器是否为一个有虚函数的类生成了 vtable 并且没有使用那个类(对象不是以任何形式创建的)。比如说, class A { public:
我对 C++ 和虚拟继承感到好奇 - 特别是解决 bass 类和子类之间的 vtable 冲突的方式。我不会假装理解它们如何工作的细节,但到目前为止我所看到的是它们是由于该分辨率而使用虚函数造成的一个
我是一名优秀的程序员,十分优秀!