It seems that you want to change the database type, from:
std::vector <Employee> *EmployeeDB;
this is a pointer to a vector, holding Employee instances. This means that the vector contains copies of employees, probably not what you want.
To:
std::vector <Employee*> EmployeeDB;
This is a vector instance, holding pointers to Employees.
You also should take care of ownership of the Employees. One solution could be handle it with new
and delete
, but the preferred one is using smart pointers:
std::vector <std::unique_ptr<Employee> > EmployeeDB;
Edit: In class definitions, the space mark does not matter when defining pointer objects.
Your two examples are the same: Character* party[3]
and Character *party[3]
mean exactly the same.
What is really important, is where the pointer mark is in templated classes definitions (inside or outside the <>
sign in the std::vector<>
specialization).
So, it is not the same having a [(vector) (of pointers)] (vector <Employee*>
), than having a [(pointer to a vector) (of instances)] (vector <Employee>*
).
1
solved C++ How to make a vector with a class type pointer