[c++] "Cannot allocate an object of abstract type" error

Error is here:

vector<Graduate *> graduates;
graduates.push_back(new AliceUniversity(identifier,id,salary,average));

Grandparent class:

Graduate::Graduate(char identifier,
                   long id,
                   int salary,
                   double average)
    : _identifier(identifier),
      _id(id),_salary(salary),
      _average(average)
{
}

Parent class:

UniversityGraduate::UniversityGraduate(char identifier,
                                       long id,
                                       int salary,
                                       double average)
    : Graduate(identifier,id,salary,average)
{
}

Actual/child class:

AliceUniversity::AliceUniversity(char identifier,
                                 long id,
                                 int salary,
                                 double average)
    : UniversityGraduate(identifier,id,salary,average)
{
    _graduateNum++;
    _sumOfGrades += average;
    _avrA = getAverage();
}

I know it's a long shot, I cant write the entire code hereā€¦

This question is related to c++ vector data-structures pure-virtual

The answer is


You must have some virtual function declared in one of the parent classes and never implemented in any of the child classes. Make sure that all virtual functions are implemented somewhere in the inheritence chain. If a class's definition includes a pure virtual function that is never implemented, an instance of that class cannot ever be constructed.


Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to vector

How to plot vectors in python using matplotlib How can I get the size of an std::vector as an int? Convert Mat to Array/Vector in OpenCV Are vectors passed to functions by value or by reference in C++ Why is it OK to return a 'vector' from a function? Append value to empty vector in R? How to initialize a vector with fixed length in R How to initialize a vector of vectors on a struct? numpy matrix vector multiplication Using atan2 to find angle between two vectors

Examples related to data-structures

Program to find largest and second largest number in array golang why don't we have a set datastructure How to initialize a vector with fixed length in R C compiling - "undefined reference to"? List of all unique characters in a string? Binary Search Tree - Java Implementation How to clone object in C++ ? Or Is there another solution? How to check queue length in Python Difference between "Complete binary tree", "strict binary tree","full binary Tree"? Write code to convert given number into words (eg 1234 as input should output one thousand two hundred and thirty four)

Examples related to pure-virtual

Error: expected type-specifier before 'ClassName' "Cannot allocate an object of abstract type" error Difference between a virtual function and a pure virtual function How do you declare an interface in C++?