The basic constructs you are using are fine, with the for loop and condition for the erase call. Unfortunately the erase method will only take iterator(s) as parameter(s).
There are a couple of ways you could do this, either way you need an iterator
|
vector<StaffMember*>::iterator iter;
|
The first way is to leave your loop control as it is. If you go for this approach you also need to increment the iterator as you loop. Initialise the iterator to the start of you vector
|
iter = employees.begin();
|
and use the
++
operator to move it through the vector as you loop.
Alternatively use the iterator to control your for loop and ditch the
int
|
for (iter = employees.begin(); iter != employees.end(); iter++)
|
Remember the iterator returned by the
end()
method is not the last item in the vector, it's off the end hence the
!=
. Less than does not work as each iterator position has no 'greater than' or 'less than' relationship with its neighbours. In contrast, the
begin()
method does point to the first item in the vector.
If you need it, you can get at the
StaffMember *
by dereferencing the iterator so for the next bit, you could get p from the iterator
or you could go straight for
In both approaches you will need to call erase with
iter
rather than
employees[i]
Go with the approach you're most comfortable with.
One last thing. You need to add in the
delete
as I mentioned in my previous post before calling
erase