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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:07:42+00:00 2026-05-14T14:07:42+00:00

Possible Duplicates: C++ method only visible when object cast to base class?! Why does

  • 0

Possible Duplicates:
C++ method only visible when object cast to base class?!
Why does an overridden function in the derived class hide other overloads of the base class?

#include <iostream>

using namespace std;

class A
{
public:
    virtual void foo(void) const { cout << "A::foo(void)" << endl; }
    virtual void foo(int i) const { cout << i << endl; }
    virtual ~A() {}
};

class B : public A
{
public:
    void foo(int i) const { this->foo(); cout << i << endl; }
};

class C : public B
{
public:
    void foo(void) const { cout << "C::foo(void)" << endl; }
};


int main(int argc, char ** argv)
{
    C test;

    test.foo(45);

    return 0;
}

The above code does not compile with:

$>g++ test.cpp -o test.exe
test.cpp: In member function 'virtual void B::foo(int) const':
test.cpp:17: error: no matching function for call to 'B::foo() const'
test.cpp:17: note: candidates are: virtual void B::foo(int) const
test.cpp: In function 'int main(int, char**)':
test.cpp:31: error: no matching function for call to 'C::foo(int)'
test.cpp:23: note: candidates are: virtual void C::foo() const

It compiles if method “foo(void)” is changed to “goo(void)”. Why is this so? Is it possible to compile the code without changing the method name of “foo(void)”?

Thanks.

  • 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-14T14:07:43+00:00Added an answer on May 14, 2026 at 2:07 pm

    The problem is, that inheritance is not carried over different namespaces. So to make it compile, you have to tell the compiler with the using directive:

    class B : public A
    {
    public:
        using A::foo;
        void foo(int i) const { this->foo(); cout << i << endl; }
    };
    
    class C : public A
    {
    public:
        using B::foo;
        void foo(void) const { cout << "C::foo(void)" << endl; }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In my .tcshrc: set history=2000 set savehist=(2000 merge) May 16, 2026 at 11:08 am
  • Editorial Team
    Editorial Team added an answer The problem is on my Linux machine Maybe ksh version… May 16, 2026 at 11:08 am
  • Editorial Team
    Editorial Team added an answer You need to reimplement QCoreApplication::winEventFilter in your QCoreApplication / QApplication… May 16, 2026 at 11:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Possible Duplicates: [.NET] How do I disable a system device? Win32 API function to
I'm writing a class to represent a Pivot Collection, the root object recognized by
Possible Duplicates: [C] Header per source file. In C++ why have header files and
Possible Duplicate: How do I use define_method to create class methods? I am trying
Possible Duplicate: How to check if an object is serializable in C# Recently found
Possible Duplicate: Can I get more than 1000 records from a DirectorySearcher in Asp.Net?
My question does not really have much to do with sqlalchemy but rather with
Possible Duplicate: John Carmack’s Unusual Fast Inverse Square Root (Quake III) I came across
Possible Duplicate: GridView current page I have a GridView ,I enabled Paging. I want
Possible Duplicate: Public Data members vs Getters, Setters In what cases should public fields

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.