在向量中找到struct

Rog*_*ier 3 c++ struct vector

我想在向量中找到一个结构,但是我遇到了一些麻烦.我读了几篇关于这个的帖子,但是这些都搜索了struct的一个元素:我希望能够在搜索时比较struct的多个元素.我的结构和向量定义为:

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;
Run Code Online (Sandbox Code Playgroud)

然后我想在向量订阅中搜索结构,但由于sessionid和matchid的组合是唯一的,我需要搜索两者.仅搜索一个将导致多个结果.

    subscription match;
    match.tournamentid = 54253876;
    match.sessionid = 56066789;
    match.matchid = 1108;
    subscriptions.push_back(match);

    it = find(subscriptions.begin(), subscriptions.end(), match);
Run Code Online (Sandbox Code Playgroud)

find函数在编译期间给出以下错误:

main.cpp:245:68:错误:'it = std :: find [with _IIter = __gnu_cxx :: __ normal_iterator>,_Tp = echo_client_handler :: subscription]((echo_client_handler*)this)中的'operator ='不匹配 - > echo_client_handler :: subscriptions.std :: vector <_Tp,_Alloc> ::以_Tp = echo_client_handler :: subscription开头,_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 :: subscription*,((echo_client_handler*)this) - > echo_client_handler :: subscriptions.std :: vector <_Tp,_Alloc>: :结束_Tp = echo_client_handler :: subscription,_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 :: subscription*,(*(const echo_client_handler :: subscription*)(&match)))'

还有更多:)所以操作员没有正确定义,但应该怎么做?谁能帮我?如何搜索多个元素而不是只搜索结构的一个元素?

ink*_*boo 6

可能是你没有指定类型it

std::vector<subscription>::iterator it = 
    find(subscriptions.begin(), subscriptions.end(), match);
Run Code Online (Sandbox Code Playgroud)