next_permutation
オブジェクトのベクトルで関数を使用する方法を理解するのを手伝ってください。パラメータを使用している人について読んだことがありcomp
ますが、理解できません。オーバーロードされた演算子が問題を解決すると思っていましたが、まだエラーがスローされています。私の構文を手伝ってください、および/または関数のcomp
パラメータを(例で)説明してくださいnext_permutation
! ありがとう!
私のメインファイルでは:
vector<Point> source;
//fill vector with Points, say 4 of them (1,2)(2,3)(3,4)(4,5)
next_permutation(source.begin(), source.end()); // at run I get error "Invalid operands to binary expression ('Const Point' and 'Const Point)"
私の単純なポイントクラス:
class Point {
private:
double xval, yval;
public:
Point(int x = 0, int y = 0) {
xval = x;
yval = y;
}
int x() { return xval; }
int y() { return yval; }
friend bool operator<(Point& lhs, Point& rhs){
return lhs.x() < rhs.x() || (lhs.x()==rhs.x() && lhs.y()<rhs.y()) ;
}
friend bool operator==(Point& lhs, Point& rhs) {
return lhs.x()==rhs.x() && lhs.y()==rhs.y();
}
};
編集:これも同じエラーをスローします:
int x() const { return xval; }
int y() const { return yval; }
friend bool operator<(const Point& lhs, const Point& rhs){
return lhs.x() < rhs.x() || (lhs.x()==rhs.x() && lhs.y()<rhs.y()) ;
}
friend bool operator==(const Point& lhs, const Point& rhs) {
return lhs.x()==rhs.x() && lhs.y()==rhs.y();
}
これも同じエラーをスローします。
int x() const { return xval; }
int y() const { return yval; }
bool operator<(const Point& lhs){
return lhs.x() < x() || (lhs.x()==x() && lhs.y()<y()) ;
}
bool operator==(const Point& lhs) {
return lhs.x()==x() && lhs.y()==y();
}