Hi G8rCre8or,
I think you might benefit from a bit of reorganisation to the design. As well as the Employee class there could a class which holds multiple employees. The vector you have on line 100 would be a private member variable of the EmployeeContainer class (you can use your own meaningful name, I just used this one because it explains what it holds), and this avoids it being a global variable - which is itself a bad idea. Then you would define an interface with public functions that allow you to interact with your vector of employees. This interface is all of the functions outside the Employee class you have already, just that they will be member functions of the EmployeeContainer class.
There is a concept called encapsulation, which means in part that all the functions & data to do with an object should be part of that object's class. If you do things how I described above, then you won't be breaking this rule.
I would be careful about making local objects in functions, better to create them in main() , and use their interface functions from there.
Another point of reorganisation is to have your class declarations in their own header files, and their implementations of their functions in a corresponding .cpp file. So have Employee.h , Employee.cpp , EmployeeContainer.h , EmployeeContainer.cpp and main.cpp . This is just a much better way to organise things.
Hope all goes well.
Edit:
Also, there is no need to have a get / set function for each member variable of a class. Get functions are reasonably benign (and are often abused), but set functions are particularly bad nearly all the time. Often it is possible to get rid of all of them.
First, you can have constructors with initialiser lists.
www.cprogramming.com/tutorial/initialization-lists-c++.html‎
|
Next, instead of doing this:
212 213 214
|
if(emp.get_name() != "") {
outfile << emp.get_name() << "\t\t" << emp.get_salary() << "\n";
}
|
Have a member function in the Employee class which does the same thing. This is also part of the encapsulation rule. This way you might be able to replace several or all of the get functions with 1 function that does output.
If you need to change the value of data members after they have been constructed: consider having one function which gets the input from the user, validates it, and then sets all the data members in one go, rather than a function for each and every data member.