Hi, I;m getting a run time: "assertion error line 238 vector iterators incompatible". When I tried debugging my program I found that the run time error occurs in the while loop in the following function.
void HRManagement::deleteEmp()
{
Employee temp;
int i;
int found=0;
cout<<"Enter the employee's ID to be deleted:\t";
cin>>i;
temp.setEmpId(i);
vector<Employee *>::iterator iter=emps.begin();
while(iter!=emps.end())
{
iter++;
if(temp==**iter)
{
found++;
cout<<"Employee record with Emp ID"<<(*iter)->getEmpId()<<"is deleted.\n";
delete *iter;
emps.erase(iter);
}
}
if(found==0)
cout<<"The employee record with the requested ID does not exist!"<<endl;
}
If you traverse a collection using an iterator, you cannot modify such collection or the iterator becomes unusable. You'll have to iterate through the collection differently, or get a new iterator every time you erase an item.