int searchEmployee(T &emp) const{
int validate = -1;
for (int i = 0; i < getNumberOfEmployees(); i++){
if (employeeContainer[i]->getEmployeeName() == emp.getEmployeeName())
if(employeeContainer[i]->getEmployeeID() == emp.getEmployeeID())
if(employeeContainer[i]->getEmployeePosition() == emp.getEmployeePosition())
if (employeeContainer[i]->getEmployeeSeniority() == emp.getEmployeeSeniority()){
validate = i;
break;
}
}
return validate;
}
In the driver file I create an employee but purposely don't add it to the employeeContainer. However, when I attempt to remove the non-existent object no exception is thrown. Is this normal? Am I doing something wrong? The search function is working as intended because it detects if am employee already exists when I'm adding an employee to avoid duplicate.
ALSO: when I attempt to remove an existing employee the function works. It only fails to throw an error/display an error.
> std::cerr << "\n" << error.what() << employeeContainer[validate]->getEmployeeID();
That line would be reached if `validate' is -1, so you are accessing the vector out of bounds.
@booradley60 No it doesn't print using std::cerr or std::cout
@helios Yeah I really don't see the point of exception here either. This is the last requirement in my stupid assignment and this is preventing me from finish... Q_Q
When I print out validate before the try block I get -1
So it's something with the exception not catching maybe?
@ne555 Yeah it gets a bit confusing, I think a more proper term would be... location?
Could it be an issue with my compiler/Eclipse run?
For clarity, I call another function x2 addEmployee(someobject)
You are invoking undefined behaviour because you are accessing an invalid index of your vector (-1)
> Yeah I really don't see the point of exception here either.
Perhaps you misread the assignment, ¿why should removeEmployee() print anything?
The try-catch block may be outside the function, like in main