#include <iostream>
#include <array>
#include <algorithm>
using namespace std;
class Test
{
private:
int value;
public:
Test()
{
}
Test(int _value)
{
value = _value;
}
bool operator<(Test&);
};
bool Test::operator<(Test& rValue) {
return this->value < rValue.value;
}
int main()
{
Test* arr = new Test[950];
arr[0] = Test(5);
arr[1] = Test(10);
arr[2] = Test(7);
arr[3] = Test(3);
arr[4] = Test(10);
sort(arr, arr + 5, [](Test& a, Test& b) { return a < b ? false : true; });
}
Sort algorithm works perfectly until there are objects with same grade value.
P.S I know other way to use sort and reverse.
I'm using visual studio 2019
ERROR: Debug Assertion Failed! Expression: invalid comparator
Testobject will have an unitializedvaluefield.operator<and use it for sorting, as!(a < b)is equal toa >= b.