ベクトルで構造体を見つけたいのですが、問題があります。これに関するいくつかの投稿を読みましたが、これらはすべて構造体の1つの要素を検索します。検索中に、構造体の複数の要素を比較できるようにしたいのです。私の構造体とベクトルは次のように定義されています。
struct subscription {
int tournamentid;
int sessionid;
int matchid;
bool operator==(const subscription& m) const {
return ((m.matchid == matchid)&&(m.sessionid==sessionid)&&(m.tournamentid==tournamentid));
}
};
vector<subscription> subscriptions;
次に、ベクターサブスクリプションで構造体を検索したいのですが、sessionidとmatchidの組み合わせが一意であるため、両方を検索する必要があります。1つだけを検索すると、複数の結果が得られます。
subscription match;
match.tournamentid = 54253876;
match.sessionid = 56066789;
match.matchid = 1108;
subscriptions.push_back(match);
it = find(subscriptions.begin(), subscriptions.end(), match);
find関数は、コンパイル中に次のエラーを出します。
main.cpp:245:68:エラー:'it = std :: find [with _IIter = __gnu_cxx :: __ normal_iterator>、_Tp = echo_client_handler :: subset](((echo_client_handler *)this)の'operator='に一致しません-> echo_client_handler :: subsets.std :: vector <_Tp、_Alloc> :: begin with _Tp = echo_client_handler :: subset、_Alloc = std :: allocator、std :: vector <_Tp、_Alloc> :: iterator = __gnu_cxx :: __normal_iterator>、typename std :: _ Vector_base <_Tp、_Alloc> :: _ Tp_alloc_type :: pointer = echo_client_handler :: subset *、((echo_client_handler *)this)-> echo_client_handler :: subsets.std :: vector <_Tp、_All :end with _Tp = echo_client_handler :: subset、_Alloc = std :: allocator、std :: vector <_Tp、_Alloc> :: iterator = __gnu_cxx :: __ normal_iterator>、typename std :: _ Vector_base <_Tp、_Alloc> :: _ Tp_ :ポインタ=echo_client_handler:: subset *、(*(const echo_client_handler :: subset *)(&match)))'</ p>
そしてもっとたくさん:)それで、演算子は正しく定義されていませんが、それはどのように行われるべきですか?誰か助けてもらえますか?構造体の1つの要素だけでなく、複数の要素を検索するにはどうすればよいですか?