The vector needs to be of type vector<Person*>
(or better yet, one of the smart pointer types like shared_ptr
or unique_ptr
) in order to do this. Otherwise, the Employee
will be sliced into a Person
when it is added, as you are seeing.
Vlad from Moscow's answer explains why this is the case.