int main()’: a.cpp:39:39: error: invalid new-expression of abstract class type ‘Student’ Person* persons[3] = {new Student(),new Teacher(),new Principal()}; ^ a.cpp:9:7: note: because the following virtual functions are pure within ‘Student’: class Student :public Person{ ^~~~~~~ a.cpp:6:18: note: virtual void Person::bellRing() const virtual void bellRing()const=0; ^~~~~~~~ a.cpp:39:53: error: invalid new-expression of abstract class type ‘Teacher’ Person* persons[3] = {new Student(),new Teacher(),new Principal()}; ^ a.cpp:18:7: note: because the following virtual functions are pure within ‘Teacher’: class Teacher:public Person{ ^~~~~~~ a.cpp:6:18: note: virtual void Person::bellRing() const virtual void bellRing()const=0; ^~~~~~~~ a.cpp:39:69: error: invalid new-expression of abstract class type ‘Principal’ Person* persons[3] = {new Student(),new Teacher(),new Principal()}; ^ a.cpp:27:7: note: because the following virtual functions are pure within ‘Principal’: class Principal:public Person{ ^~~~~~~~~ a.cpp:6:18: note: virtual void Person::bellRing() const virtual void bellRing()const=0; ^~~~~~~~
时间: 2023-06-04 16:06:47 浏览: 183
这是一个编程问题,可能需要进一步的代码审查才能确定问题的根源。但是,我可以看出代码中有一个抽象类“Person”,它有一个纯虚函数“bellRing()”,而“Student”、“Teacher”和“Principal”都继承了“Person”且没有实现“bellRing()”函数,导致编译错误。正确的做法是在“Student”、“Teacher”和“Principal”中实现“bellRing()”函数,或者将“Person”中的“bellRing()”函数改为非纯虚函数。
阅读全文