Hi all, I need some little help getting my head out of this , my problem is I want to construct two classes.
1. Employee
- name, salary, work ID
- each employee can accomplish several task so I will make a vector of
tasks
pretty simple
2 manager
- name, some more details
- the manager have a list of all employees in the
organization. He can also send messages to the employees if they fail
to accomplish a task in five days after which he can fire them.
i just cant gwt an idea on how these ↓↓↓↓↓↓ can be done If I create a bunch of 'em employees, they should be added to the
manager list ,the manager will monitor the employees and can fire them.
↑↑↑↑
@shadowcode bright idea there, I can see a container will get my job done yea, I can make it carry pointers to employee objects so that only a single employee can exists, if fired you need only get one object going "I hope that's the case".
Btw av got another qstion to get it working.
How will I add objects immediately they are created to the vector? Is it possible to do it in the employee constructor ? That is what I would like . If so what relationship need be there between the employee and manager classes for this to happen.
Is it possible to do it in the employee constructor ?
The constructor creates the object. Consider this..
1 2 3 4 5
Employee::Employee()
{
..... //here the object is still under construction
}
//the object is now completely created and now can be passed to the manager's list.
So to answer your question, you cannot add an employee object to the Manager's employee list in the constructor of the employee object.
class Employee
{
//alot of code here
}
class Manager
{
void addtolist (Employee* new_emp);
void addcopy (Employee new_emp);
//code here
vector<Employee*> emp_list (0);//uses pointers
vector<Employee> emp_copy_list (0);//just for demo
}
void Manager::addtolist (Employee* new_emp)
{
emp_list.push_back (new_emp);
}
void Manager::addcopy (Employee new_emp)
{
emp_copy_list.push_back (new_emp);
}
int main ()
{
Employee* emp_obj= new Employee;
Manager manager;
manager.addtolist (emp_obj);// I only passed the same object
manager. addcopy (*emp_obj);// passed a copy of the employee
}
you cannot add an employee object to the Manager's employee list in the constructor of the employee
I guess this means i'll have to make another function that will add employee objects, i'll post my code when am through so you can help me find where I missed a point.