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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:55:37+00:00 2026-06-05T10:55:37+00:00

The following code: class Base1 { public: void go() {} }; class Base2 {

  • 0

The following code:

class Base1
{
public:
    void go() {}
};

class Base2
{
public:
    void go(int a) {}
};

class Derived : public Base1, public Base2 {};

int main()
{
    Derived d;

    d.go(3);

    return 0;
}

will give an error during compilation:

g++ -o a a.cc
a.cc: In function ‘int main()’:
a.cc:19:7: error: request for member ‘go’ is ambiguous
a.cc:10:10: error: candidates are: void Base2::go(int)
a.cc:4:10: error:                 void Base1::go()
make: *** [a] Error 1

It’s easy to see the prototypes in base classes are different. But why cannot the compiler detect this and automatically choose the matching one?

  • 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-05T10:55:40+00:00Added an answer on June 5, 2026 at 10:55 am

    Function overloading is not allowed across class boundaries.
    You can fix this by writing the Derived class like so –

    class Derived : public Base1, public Base2
    {
    public:
        using Base1::go;
        using Base2::go;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting error with the following code: import java.util.Scanner; public class FahrenheitToCelsius{ public static void
Lets assume we have the following code: abstract class Base1 { protected int num;
Consider the following code: class Base { void f() { } }; class Derived:
Consider the following code: template<int* a> class base {}; int main() { base<(int*)0> test;
I have the following code: class Base { public: int x,y; Base() { x=10;
This is my c++ code: class base { public: int bval; base(){ bval=0;} void
Consider the following sample code: class Base { public: void f(); virtual void vf();
Consider the following code: public abstract class Base { public void getAnswer(); } public
The following code is giving compilation error: template <typename T> class Base { public:
Given the following block of code: class BaseClass { public: virtual void hello() {

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.