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 6986047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:45:33+00:00 2026-05-27T18:45:33+00:00

I am stumped by why the declaration of void operator()(int) in the base class

  • 0

I am stumped by why the declaration of void operator()(int) in the base class in the code sample below is seemingly hidden when the derived class implements void operator()(int,int,int). How can I get the declaration of operator()(int) from the base class foo to be visible in the derived class bar? That is, how can I modify the example so that the invocation of operator()(int) works?

#include <iostream>

struct foo
{
        void operator()(int)
        {
                std::cout << "A" << std::endl;
        }
};

struct bar : foo
{
        // If this is uncommented, the code will not compile.
        // void operator()(int, int, int) {}
};

int main()
{
        bar b;
        b(1);
        return 0;
}

When compiled with g++ with the marked lines uncommented, the error message is along the lines of “no match for call to ‘bar (int)’ … candidate is void bar::operator()(int,int,int) … candidate expects 3 arguments, 1 provided.”

  • 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-05-27T18:45:34+00:00Added an answer on May 27, 2026 at 6:45 pm

    That’s right. Derived class functions hide base class functions rather than overloading. The fix is pretty simple though:

    struct bar : foo
    {
         using foo::operator();
         void operator()(int, int, int) {}
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm re-factoring some inherited code, but was stumped by the design decision and can't
I am completely stumped as to why this code does not get any SDL
I am stumped. The code is exactly the same and they are both hosted
Stumped for want of a seemingly reasonable programming logic.. Am inside a script task
Stumped with a OOP interface F# question. Example - when I create a class
/*I got stumped within my code. I think classes will be simpler than structures,
I am stumped as to why this code compiles with type hints, but does
I'm stumped by this seemingly trivial problem... I would like to use python to
I am completely stumped. I have a program that pulls information stored in a
I'm completely stumped on this one. I have three different lists that need to

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.