如果一个虚函数不是纯虚函数,父类需要实现它。否则就会报错:undefined reference to vtable XXX
例如:
class a
{
public:
virtual bool fun();
}
class b:public a
{
virtual bool fun(){cout << “I am b” << endl;}
}
以上代码编译时会报错undefined reference to vtable XXX
修改为:
class a
{
public:
virtual bool fun(){cout << “IamA” << endl;};
}
class b:public a
{
virtual bool fun(){cout << “I am b” << endl;}
}