I am receiving the following error compiling in Visual Studio 2010.
Debug Assertion Failed!
Expression: invalid operator<
It is a result of the following comparison function:
bool ShortestJob(Process_T *first, Process_T *second)
{
int firstRemaining = first->cpuTime - first->cpuProgress;
int secondRemaining = second->cpuTime - second->cpuProgress;
if ((firstRemaining < secondRemaining) || ((first->cpuProgress == second->cpuProgress) && (first->processID < second->processID))) {
return true;
} else {
return false;
}
}
The field processID is an int. How may I resolve this bug?
Visual Studio 2010 will assert in debug build if your compare function object for sorting is incorrect and doesn’t follow strict weak ordering.
Try changing your function to
They way you have defined the operator is incorrect. You should only compare processID for if and only if the first criteria which in your case is (firstRemaining ,secondRemaining) are equal