はい、私はこれが繰り返しの質問であることを知っており、私が探しているアンサーがここにあることをすでに知っています:
オブジェクトのプロパティによるオブジェクトのベクトルのソート
ただし、これを自分のコードに変換する際に問題があります。上記の質問からこのコード スニペットを見ています。
struct SortByX
{
bool operator() const(MyClass const& L, MyClass const& R) {
return L.x < R.x;
}
};
std::sort(vec.begin(), vec.end(), SortByX();
私が理解していないのはMyClass const & L
、 、および によって表されているものですMyClass const & R
。そして、これを自分のコードに適用する方法を理解していません。
もう少し詳しく説明すると、( 、 、 、string
)double
のdouble
パラメーターを持つオブジェクトのベクトルのラッパー クラスに 3 つの並べ替えメソッドを入れています。全体的な目標は、、 、および 3 つの double のうちのいずれかでソートすることです。double
bool
vector
string
bool
これは私が持っている最新のバージョンです:
void StationVector::sortByGrade(int kindOfGas) {
struct SortByGrade {
int kindOfGas;
SortByGrade(int kindOfGas) :
kindOfGas(kindOfGas) {
}
bool operator()(GasStation const &L, GasStation const & R) const {
return L.getPrice(kindOfGas) < R.getPrice(kindOfGas);
}
};
std::sort(localStations.begin(), localStations.end(),
SortByGrade(kindOfGas));
}
行SortByGrade(kindOfGas))
は私に次のエラーを与えます:
`sort(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, model::StationVector::sortByGrade(int)::SortByGrade)' の呼び出しに一致する関数がありません