I have class A, in which there is a member variable of class B. And in B, there is a member variable of priority_queue "q" and I want to define a customized comparator class C for it. But for the comparator, the comparison needs a member variable "f_val" from A.
Since the original code is long, the basic idea is as follows:
class C
{
map<Point,double> f_val;
C(double f_val1)
{
f_val=f_val1;
}
bool operator () (const Point &pt1, const Point &pt2)
{
return f_val[pt1] > f_val[pt2];
}
};
class A
{
B b;
map<Point,double> f_val;
}
class B
{
B(map<Point,double> f_val1){f_val=f_val1;}
priority_queue<Point,vector<Point>,C(f_val)> q;
map<Point,double> f_val;
}
Aucun commentaire:
Enregistrer un commentaire