c++ 编译报错汇总(随时更新)

时间:2023-03-09 04:13:14
c++ 编译报错汇总(随时更新)

1、invalid new-expression of abstract class type ‘×××ב

这个报错代表一个尝试在实例化一个抽象类,也就是说父类的接口中有纯虚函数在子类中没有实现;

举例:

//父类
class parent:
{
virtual ~parent();
virtual void func1() = ;
}; //子类
class child: public parent
{
child();
~child();
}; int main()
{
parent *test = new child();
};

这样编译就会报错,子类中必须要实现所有父类里面定义的纯虚函数

正确方式如下:

class parent:
{
virtual ~parent();
virtual void func1() = ;
}; class child: public parent
{
child();
~child();
void func1() {}
} int main()
{
parent *test = new child();
};

2:error: cannot declare variable ‘bbb’ to be of abstract type ‘aaa’

note:   because the following virtual functions are pure within ‘aaa’:

一般是class aaa中有纯虚函数没有实现导致