In the comments you said that your vector is declared as:
std::vector<Student> vector_of_Student_object;
...and therein lies the problem. You trying to store Student
objects in the vector
, but you can't store a Student
object because that class is abstract. Consider the following psudocode:
void foo(Student s)
{
}
int main()
{
SoftwareStudent ss;
foo(ss);
}
What happens to ss
when foo
is called? You are passing a SoftwareStudent
, but foo
just takes a Student
. So ss
is implicitly converted to its base class, Student
which, since foo
takes a Student
by value, tries to construct a new Student
by calling:
Student::Student(const Student& rhs)
In other words, the SoftwareStudent
-specific attributes of ss
You may not have implemented this constructor yourself, in which case the compiler did it for you.
The end result is you are trying to instantiate an abstract class because foo
takes a Student
by-value. This obviously won't work since you can't instantiate an abstract class.
This relates to your actual problem because your vector
is a vector
of Student
objects, stored again by value. When you insert an object in to a vector, that object is copied. You end up trying to instantiate Student
objects, which you can't do because Student
is abstract.
You need to store something other than Student
, either a Student
reference or pointer. Since you can't have a vector
of references, that leaves you with pointers.
Whenever dealing with pointers, it's best to deal with smart pointers rather than raw pointers as with smart pointers you don't need to worry as much about releasing the object, and very often you don't even have to use new
explicitly. std::shared_ptr
is probably the easiest to incorporate here, although std::unique_ptr
might be a better fit semantically.