I need to implement two classes.
One should contain an Employee with no methods, just constructor.
Second one should have std::vector container in with all the Employers made inside it, and few methods to manipulate those objects for example to add new employee or change his id.
After many attempts with errors im stuck and i dont know how to pass created employees to container in second class. I dont even know how the HR class should look like (its constructor should only have container?) and how it can make this container of Employee class objects.
First class is Employee.h, Employee.cpp and second is HR.h, HR.cpp
Here is my Employee.h
#include <iostream>
class Employee {
public:
std::string id;
std::string name;
std::string surname;
std::string departmentId;
std::string position;
Employee(std::string id, std::string name, std::string surname, std::string departmentId, std::string position);
~Employee();
};
Employee.cpp
#include "Employee.h"
#include <iostream>
#include <vector>
Employee::Employee(std::string xid, std::string xname, std::string xsurname, std::string xdepartmentId, std::string xposition) : id (std::move(xid)), name (std::move(xname)), surname (std::move(xsurname)), departmentId (std::move(xdepartmentId)), position (std::move(xposition))
{
std::cout << "constructor of worker"<< std::endl;
std::cout << "id:" + this->id + " name:" + this->name + " surname:" + this-> surname + " department:" + this->departmentId + " position:" + this->position << std::endl;
};
Employee::~Employee()
{
std::cout << "destructor"<< std::endl;
};
main.cpp
#include <iostream>
#include <vector>
#include "Employee.h"
#include "HR.h"
int main() {
std::vector < Employee > all;
Employee first("2","John","Smith","1","c++ developer");
Employee second("3","Steven","McDonald","2","administrator");
Employee third("4","Mark","Johnson","1","c++ developer");
all.push_back( first );
all.push_back( second );
all.push_back( third );
system("pause");
return 0;
}
I made this std::vector in main.cpp which i know is based wrong and it should be in second class, its there just to test it.
Should i place this push_back in Employee constructor and throw it somehow to HR class everytime new employee is created?
I'm really stuck right here.
EDIT: HR.h code - it's almost nothing there. I moved std::vector from main.cpp to HR.h but i dont know how to implement it.
#include "Employee.h"
#include <vector>
class HR {
public:
static std::vector < Employee > all;
HR();
~HR();
};
HR.cpp
#include <iostream>
#include <vector>
#include "HR.h"
HR::HR()
{
std::cout << "constructor HR"<< std::endl;
};
HR::~HR()
{
std::cout << "destructor HR"<< std::endl;
};
Aucun commentaire:
Enregistrer un commentaire