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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:04:50+00:00 2026-06-04T21:04:50+00:00

I have a C++ base class which declares a virtual method with two different

  • 0

I have a C++ base class which declares a virtual method with two different signatures.

As soon as I override one of the virtual method signatures in a derived class the compiler (g++ 4.6.3 and g++ 4.7) is no longer able to match the method with the second signature in the same derived class.

The example code below will not compile if I only define SPECIALIZE_ONEARG to 1. In order to get it to compile again I also have to define PASSTHRU_TWOARG to 1. Using the “PASSTHRU” method isn’t ideal because of efficiency and because the real class hierarchy is much deeper and I would prefer not to hardwire in the call to the base class.

Is this behavior specific to g++ or am I just trying to do something which isn’t supported in C++?

#define SPECIALIZE_ONEARG ( 0 )
#define PASSTHRU_TWOARG   ( 0 )

class base
{
public:
  virtual int myMethod( char a )         { return 1; }
  virtual int myMethod( char a, int b )  { return 2; }
};

class derived : public base
{
public:
#if SPECIALIZE_ONEARG
  virtual int myMethod( char a )         { return 3; }
#endif // SPECIALIZE_ONEARG

#if PASSTHRU_TWOARG
  virtual int myMethod( char a, int b )  { return base::myMethod( a, b ); }
#endif // PASSTHRU_TWOARG
};

int main( int argc, char* argv[])
{
  derived myObj;

  return myObj.myMethod( 'a' ) * 10 + myObj.myMethod( 'b', 0 );
}
  • 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-04T21:04:52+00:00Added an answer on June 4, 2026 at 9:04 pm

    Your definition is hiding the definition from the base class. In order for that definition to be visible at your derived scope, you need using base::myMethod.

    class derived : public base
    {
    public:
      using base::myMethod; // <--- here
    
    #if SPECIALIZE_ONEARG
      virtual int myMethod( char a )         { return 3; }
    #endif // SPECIALIZE_ONEARG
    
    #if PASSTHRU_TWOARG
      virtual int myMethod( char a, int b )  { return base::myMethod( a, b ); }
    #endif // PASSTHRU_TWOARG
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have a pure virtual class Base, and a concrete class Derived which
Ok, so I have a base class which declares the event StatusTextChanged . My
I have a class which is derived from a base class, and have many
I have a base Entity class which will be derived in more than a
I have a base class which is non-generic with a derived generic class. The
I have the following abstract base class in which i have an abstract method.
I have my class X which inherits from Qt's class Base . I declared
I want to have a base class which dictates the alignment of the objects
I have a Exception base class which defines a stream function: class Exception {
I have my own base abstract class which extends Activity class. public abstract class

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.