Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:28:17+00:00 2026-06-06T22:28:17+00:00

I want to find a struct in a vector, but I’m having some troubles.

  • 0

I want to find a struct in a vector, but I’m having some troubles. I read several posts about this, but these all search for one element of the struct: I want to be able to compare multiple elements of the struct while searching. My struct and vector are defined as:

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;

Then I want to search for a struct in the vector subscriptions, but since the combination of sessionid and matchid is unique, I need to search for both. Searching for only one will result in multiple results.

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

    it = find(subscriptions.begin(), subscriptions.end(), match);

The find function give the following error during compiling:

main.cpp:245:68: error: no match for ‘operator=’ in ‘it = std::find [with _IIter = __gnu_cxx::__normal_iterator >, _Tp = echo_client_handler::subscription](((echo_client_handler*)this)->echo_client_handler::subscriptions.std::vector<_Tp, _Alloc>::begin with _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>::end with _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)))’

And a WHOLE lot more 🙂 So the operator is not defined correctly, but how should that be done? Can anyone help me? How to search for multiple elements instead of only one element of a struct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:28:19+00:00Added an answer on June 6, 2026 at 10:28 pm

    May be you did not specified type for it?

    std::vector<subscription>::iterator it = 
        find(subscriptions.begin(), subscriptions.end(), match);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find the first item in a sorted vector that has a
I want to find about the HTTP 1.1 compression of the site I am
I want to create a struct like this in MySQL: CREATE TYPE EMP_DATA( SSN
I'm facing some trouble to find the best way to return an struct with
I have this structure which I want to write to a file: typedef struct
I want to know how to read a struct within a struct via php's
This code below compiles fine with VS2010 but doesn't want to compile with gcc
So this is pretty basic, but I don't really know C. I want to
I want find all Saturdays and Sundays in A given month. How can I
I want to find which tables are related to a specific table. I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.