Re: [Dev-C++] Newbie class/vector/implementation problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-05-27 21:31:06
|
First of all, A variable type Employee should be a single employee and not a container object. The nameing is confusing. Secind - why a vector? Are empoloyees a numbered, continuous sequence? I would more think of a map, which maps from an employee identifier (employment sequence number or whatever) and the employee data. Then you might write an DeleteEmployee() fnctions that takes the key value of an employee and locates the employee in the map. You might also remove an employee directly by iterating through the map and using the iterator to specify which employee to delete. If you can have only a single map of employees (you were planning on declaring your vector in the implementation file) you don't need any reference to the container in your deleteEmployee() and addEmployee() calls. If addEmployee() and deleteEmployee() are ordinary functions they might access the employees container as a static global variable inside the implementation file. However, you should think about your need to write specific functions for add and remove of employees. If you want to perform special actions it might be an idea to create an Employees class owning the container and having add()/remove() as methods. If no extra work is needed, you don't need addEmployee(), deleteEmployee() since you may operate directly on the container. /Per W On Thu, 27 May 2004, Dane Ensign wrote: > Hi, > > First, thank you in advance for any help you can offer. > > Im working on a very limited and elementary program and I need help > setting it up correctly. > I have made a basic Employee class. I want to make a vector of Employee > objects. I need > to be able to add, delete, and update Employee data, which is why I > think I need a vector of them. > > To begin with, I think that I would include the <vector> in my Employee > implementation file. > Then declare an Employee vector. When the user wanted to delete one, I > would pass an indexed Employee vector as a parameter into a > deleteEmployee() function. > Would the function headerline look like this? > > void deleteEmployee(Employee Emp ()) // Employee is the class, and Emp > is the name of the vector. > > Once I have successfully passed the Employee vector (i) into the > function I think I would use a vector class function > like: > vectorList.erase( i ); > > to delete the employee record. How does this look to you? > > Dane > > > > > > ---------------------------------------------------- |