简单继承获得虚值表错误
Simple Inheritance Gets Vtable Error
所以我试着编译这个简单的代码:
// In Test.h
#include <iostream>
using namespace std;
class A{
public:
virtual string f (string&);
};
class B : public A{
public:
B (string);
string f (string&);
};
// In Test.cpp
#include <iostream>
#include "Test.h"
using namespace std;
B :: B (string row){
cout << "HERE";
}
string B :: f (string& x){
cout << "Test";
}
这似乎很简单,但我一直得到一个Undefined reference to 'vtable for A'
错误(编译器是MINGW与Eclipse IDE)。当我取出B的构造函数实现时,代码编译得很好。我错过了什么,还是这是一个链接错误?
我认为您要么必须通过在声明末尾编写= 0
来使A::f(string&)
抽象,要么实际上提供A::f
的实现
由于当前虚函数A::f
不存在,编译器不能为它创建虚函数表
相关文章:
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 在 c++ 中拆分类和标头中的继承,错误
- enable_if继承的成员函数的名称查找错误
- C++模板类 - 继承调用错误的函数
- C++ 中的构造函数、继承、堆栈、堆、this-pointer 和段错误
- 为什么这个混合继承程序给出错误的输出?
- 使用多重继承时出现编译错误
- 多级继承错误 C2280:"atttempting to reference a deleted function"
- 相对于继承的构造函数,gcc 编译器是否还有一个错误?
- 从模板继承的 MSVC DLL 导出类会导致LNK2005已定义的错误
- 模板化类继承的子类定义中的错误
- C++错误LNK2005和不同项目文件的常规继承
- 错误:'int_type'未命名类型 - 如何继承 typedefs 和用法
- 在 soap_ssl_server_context(..) 中使用继承时 gsoap 中的分段错误
- C++中的继承,"...is an ambiguous base of ..."错误
- 与lambda一起使用虚拟继承在初始化列表中捕获此问题的GCC错误
- 收到未定义的引用错误 c++ 继承/多态性
- c++错误:继承转换无效
- 错误继承不能访问c++的方法