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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:28:43+00:00 2026-05-16T20:28:43+00:00

Ok, I’m using virtual functions, overloaded functions, and multiple inheritance. Of course this doesn’t

  • 0

Ok, I’m using virtual functions, overloaded functions, and multiple inheritance. Of course this doesn’t turn out well.

The scenario: Class base1 has a virtual function that needs to be specified by its child.
Class derived derives from two parents base1 and base2, and should use base2‘s existing functionality to define base1‘s virtual function.

This is ok, but awkward of course. The motivation is I cannot change the class base2 and the existing interface already heavily invested in has base1 and base2 class functions of the same name. This is ok, nothing is implemented in base1, it should just redirect to base2.

My problem arises because base2 has several overloaded functions of the same name as the virtual function in question. All of the other overloaded versions become essentially hidden at compile time.

Here’s a small demonstration code.

// this version does not compile, overloaded samenameFunc(int, int) cannot be found in the derived class.
#include <iostream>
using namespace std;

class base1 {
public:
    virtual void samenameFunc(int scratch) { cout << "from base1: " << scratch << std::endl; }
};

class base2 {
public:
    void samenameFunc(int scratch) { cout << "samenameFunc from base2: " << scratch << std::endl; }
    void samenameFunc(int scratch, int foo)  { cout << "samenameFunc(2 args) from base2: " << scratch << ", " << foo << std::endl; }
};

class derived : public base1, public base2 {
public:
    void samenameFunc(int scratch) { base2::samenameFunc(scratch); }// { cout << "from derived: " << scratch << std::endl; }
};

int main()
{
    derived d;

    d.samenameFunc(66);
    d.samenameFunc(77, 88);
    return 0;
}

And the compiler errors:

$ g++ inheritance_overload_tester.cc 
inheritance_overload_tester.cc: In function ‘int main()’:
inheritance_overload_tester.cc:26: error: no matching function for call to ‘derived::samenameFunc(int, int)’
inheritance_overload_tester.cc:18: note: candidates are: virtual void derived::samenameFunc(int)

If the overloaded samenameFunc(int, int) is renamed, I can compile and function as expected. But remember, I can’t actually change base2.

// this version does compile
#include <iostream>
using namespace std;

class base1 {
public:
    virtual void samenameFunc(int scratch) { cout << "from base1: " << scratch << std::endl; }
};

class base2 {
public:
    void samenameFunc(int scratch) { cout << "samenameFunc from base2: " << scratch << std::endl; }
    void anotherFunc(int scratch, int foo)  { cout << "anotherFunc(2 args) from base2: " << scratch << ", " << foo << std::endl; }
};

class derived : public base1, public base2 {
public:
    void samenameFunc(int scratch) { base2::samenameFunc(scratch); }// { cout << "from derived: " << scratch << std::endl; }
};

int main()
{
    derived d;

    d.samenameFunc(66);
    d.anotherFunc(77, 88);
    return 0;
}

If this can’t be fixed in the existing presentation, can someone suggest a different object inheritance model to solve my problem?

  • 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-16T20:28:43+00:00Added an answer on May 16, 2026 at 8:28 pm

    In the definition of the derived class, you can add a using declaration to make the function from base2 visible:

    using base2::samenameFunc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
In order to apply a triggered animation to all ToolTip s in my app,

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.