#include <stdio.h>
class A {
public:
virtual void print();
A();
};
class B :public A {
public:
void print();
B();
};
class C :public B {
public:
void print();
C();
};
A::A(){
}
B::B(){
}
C::C(){
}
void B::print() {
printf("From B\n");
}
void C::print() {
printf("From C\n");
}
int main() {
B* object = new C;
object->print();
return 0;
}
当我尝试编译此 C++ 文件时,出现以下错误。想不通原因。我尝试阅读关于 SO 的类似未定义 vtable 问题。
/tmp/ccpOkVJb.o: In function `A::A()':
test1.cpp:(.text+0xf): undefined reference to `vtable for A'
/tmp/ccpOkVJb.o:(.rodata._ZTI1B[_ZTI1B]+0x10): undefined reference to `typeinfo for A'
collect2: error: ld returned 1 exit status