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

  • Home
  • SEARCH
  • 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 8631315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:12:09+00:00 2026-06-12T09:12:09+00:00

I have a program structured similiar to: class A { private: std::set<B> members; public:

  • 0

I have a program structured similiar to:

class A {
    private:
        std::set<B> members;
    public:
        void func(const C& arg) {
            std::set<B>::iterator iter = members.find(a);
            if(iter != members.end()) {
                iter->check(arg);
            }
        }
}



class B {
    private:
        std::deque<C> writers;
    public:
        void check(const C& arg) {
            if(std::find(writers.begin(), writers.end, arg) != writers.end()) {
                /* Code */
            }
        }
}


class C {
  private:
      int id;
  public:
      bool operator==(const C& arg) {
          return arg.id == this->id;
      }
}

When I compile this, I get the following error message:

no matching function for call to ‘B::check(const C&) const’  
note: candidates are: void B::check(const C&) <near match>

If I declare check() as const then the compiler throws an error demanding that the overloaded operator == in Class C to be declared as const. I don’t know if making the overloaded operator as const is the right thing to do. (I tried it once and as far as I can recollect it also gave some error).

I been trying to solve this for more than five days and still no leads.

  • 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-12T09:12:10+00:00Added an answer on June 12, 2026 at 9:12 am

    The first thing is that operator== should be const. It does not modify data, nor should it ever unless you want to confuse your users. In general every function that need not modify the state of the object should be const as to provide the maximal flexibility (i.e. allow calls through constant references).

    The same can be applied to B::check, if it does only test and not modify, then it should be const. And by extension in A::func, if it does not need to modify then it should be const.

    The error message will be slightly different in different compilers. In your case the compiler performed overload resolution and did not find a match to the call which is what it complains about:

    no matching function for call to ‘B::check(const C&) const’
    note: candidates are: void B::check(const C&)

    Which indicates that it saw your member but discarded it as it needed a member function with the const tag. In other compilers the error message will contain something on the lines of: calling void B::check(const C&) discards qualifiers which is a bit more convoluted and tries to say that calling a non-const member function on a const reference would require ignoring the const qualifier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that load data from a file using std::ifstream and store
I have a program structure like following : int firstFunction(unsigned char *firstValue, int s,
I have a program which places structures in a linked list based on the
I have a python program which calls a C function. I send some structures
I have a speed critical multithreaded program which involves data in a tree structure.
I have a pointer of a structure type that I made. On program start
I have the need to use a Stack-like data structure for a program that
I have program written in C. It takes 2 arguments username/password and try to
I have program that requires Python 3, but I develop Django and it uses
I have program that has a variable that should never change. However, somehow, it

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.