“Cannot allocate an object of abstract type” error

前端 未结 2 750
一向
一向 2020-12-30 20:37

Error is here:

vector graduates;
graduates.push_back(new AliceUniversity(identifier,id,salary,average));

Grandparent clas

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 21:19

    In C++ a class with at least one pure virtual function is called abstract class. You can not create objects of that class, but may only have pointers or references to it.

    If you are deriving from an abstract class, then make sure you override and define all pure virtual functions for your class.

    From your snippet Your class AliceUniversity seems to be an abstract class. It needs to override and define all the pure virtual functions of the classes Graduate and UniversityGraduate.

    Pure virtual functions are the ones with = 0; at the end of declaration.

    Example: virtual void doSomething() = 0;

    For a specific answer, you will need to post the definition of the class for which you get the error and the classes from which that class is deriving.

提交回复
热议问题