C++ 编译出现undefined reference to `vtable for Class 和 undefined reference to typeinfo for Class

时间:2022-11-28 05:28:25

在使用虚函数的程序中,编译时会出现

      undefined reference to `vtable for Class 

或  undefined reference to typeinfo for Class 

的情况

其解决方案就是将类似于

virtual void foo();

Should be defined (inline or in a linked source file):

virtual void foo() {}

Or declared pure virtual:

virtual void foo() = 0;