storage of employee objects in a container
-
I want to store a group of employee objects in an array or collection of some type and then be able to find which employees are of a certain department number. For example there may be a total of 10 employees with 4 of the employees belonging to department 1 and the rest to various other departments, I want to be able to find all of the employees belonging to department 1 and print those out. What do you think is the best way to do this? I tried to use a vector sequence container, but I don't know how I would find multiple employee objects depending on dept number attribute. Any help would be greatly appreciated, Jason
-
I want to store a group of employee objects in an array or collection of some type and then be able to find which employees are of a certain department number. For example there may be a total of 10 employees with 4 of the employees belonging to department 1 and the rest to various other departments, I want to be able to find all of the employees belonging to department 1 and print those out. What do you think is the best way to do this? I tried to use a vector sequence container, but I don't know how I would find multiple employee objects depending on dept number attribute. Any help would be greatly appreciated, Jason
-
You could have a map containing vectors. The map key would be the department number, and the data would be a vector (or better, a pointer to a vector) of employees.
Steve S Developer for hire
But what if there were multiple map key's (department number's) that are the same? It would only show the first occurance, right? Is there a way I can show all objects of that same key? Thanks, Jason
-
I want to store a group of employee objects in an array or collection of some type and then be able to find which employees are of a certain department number. For example there may be a total of 10 employees with 4 of the employees belonging to department 1 and the rest to various other departments, I want to be able to find all of the employees belonging to department 1 and print those out. What do you think is the best way to do this? I tried to use a vector sequence container, but I don't know how I would find multiple employee objects depending on dept number attribute. Any help would be greatly appreciated, Jason
-
But what if there were multiple map key's (department number's) that are the same? It would only show the first occurance, right? Is there a way I can show all objects of that same key? Thanks, Jason
Do you mean that there are multiple departments with the same number, or that there are multiple employees in the same department? If the former, then you cannot use department number as a key, since you cannot be sure which distinct department you should be referring to. If the latter, that's why the data is a vector, so you can add multiple employees.
Steve S Developer for hire
-
Do you mean that there are multiple departments with the same number, or that there are multiple employees in the same department? If the former, then you cannot use department number as a key, since you cannot be sure which distinct department you should be referring to. If the latter, that's why the data is a vector, so you can add multiple employees.
Steve S Developer for hire
The latter, multiple employees in the same department. How would I use a vector inside of a map? I tried the following example but received an error C2665 'std::pair<_Ty1,_Ty2>::__ctor' : none of the 3 overloads can convert parameter 2 from type 'const char [5]'
typedef map > EmployeeType; void MapVectorTest() { EmployeeType theMap; EmployeeType::iterator theIterator; theMap.insert(EmployeeType::value_type(0, "Zero")); // error C2665 }
-- modified at 14:43 Friday 2nd March, 2007 Thanks, Jason -- modified at 14:48 Friday 2nd March, 2007