#include <iostream>
#include <queue>
struct Point
{
Point(int p_x,int p_y):x(p_x),y(p_y){}
int x;
int y;
};
class ComparePoints
{
public:
bool operator()(Point *p1,Point *p2) const
{
if ((p1->x*p1->x + p1->y*p1->y) > (p2->x*p2->x + p2->y*p2->y))
return true;
else if ((p1->x*p1->x + p1->y*p1->y) == (p2->x*p2->x + p2->y*p2->y))
return rand() % 2;
return false;
}
};
int main()
{
std::priority_queue < Point*, std::vector<Point*>, ComparePoints> q;
for (int i = 0; i < 10; ++i)
q.push(new Point(rand() % 10, rand() % 10));
for (int i = 0; i < 10; ++i)
{
std::cout << q.top()->x << " " << q.top()->y << std::endl;
q.pop();
}
system("pause");
return 0;
}
Jak uruchamiam program to wyrzuca mi wyjątek "invalid comparator". Jak debugowałem program to dzieje się tak przy którejś operacji push. O co tu może chodzić?