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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:13:35+00:00 2026-05-30T21:13:35+00:00

I want to know if there is a way to specify that in multiple

  • 0

I want to know if there is a way to specify that in multiple inheritence, one of the base-classes virtual functions becomes the single virtual definition. They only way I see to do this is by writing an explicit definition of this function in the derived class and explicitly call one of the base classes. This is cumbersome, and I was hoping using might help, but it doesn’t.

For example, in the below code, I have to define a C::value even though I just wish to forward to the class B version. Is there not a simpler way?

#include <iostream>

using namespace std;

struct A
{
    virtual char const * value() const
    { return "A"; }
};

struct B
{
    virtual char const * value() const
    { return "B"; }
};

class C : public A, public B
{
public:
    //using B::value;
    virtual char const * value() const
    { return B::value(); }
};

int main()
{
    C obj;
    cout << obj.value() << endl;

    A * ptr = &obj;
    cout << ptr->value() << endl;
}

Some notes:

  • in this particular case virtual inheritance of class A is not an option for Class B — I need a proper construction chain down to the base
  • In theory struct B could also be used unrelated to A, but that is not the case here (in case that provides other options)
  • value may be marked as pure virtual if that somehow helps, but I don’t believe it does.
  • there are other classes which derive from A but not B
  • to be clear, however “func” is called on C, through any type pointer, must result in “B”

I suspect the answer might be “No”, but some confirmation would be good. It feels like the language should support this pattern.

  • 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-30T21:13:36+00:00Added an answer on May 30, 2026 at 9:13 pm

    The only way I see to do this is by writing an explicit definition of
    this function in the derived class …, and I was hoping using might
    help

    using keyword in your context is used only to bring the names into the current scope (used against name hiding). Assume that your requested feature is already there. Now see the below modified codes:

    struct A
    {
      virtual char const * value() const
      { return "A"; }
    
      void value (double);  // new function
    };
    
    class C : public A, public B
    {
    public:
      using B::value;
      void value(int);  // new function
    };
    

    Suppose we have functions of the same name as value(int) in C and value(double) in A. These 2 functions have nothing to do with virtual value() and are used with object of C.

    How will you use A::value(double) with C‘s object ? Naturally you have to do using A::value; in body of C. Now because of this, as a side effect we have 2 virtual function match: A::value() const and B::value() const!
    Which to choose when called with A* or B* ?

    This is only one example, but there can be other problems too. Whatever you have mentioned in your question is the best way to accomplish the correct result. It explicitly says that C::value() const is a wrapper around B::value() const.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know is there any way that I can remove duplicates from
Is there a way using NSRegularExpression to specify that you want to do a
I want to know is there any way or message in MFC by which
I want to know if there is any way by which I can paste
I want to know if there is a better way (than what I'm currently
All I want to know is if there's an easy way to add lines
i want to know there a limitation in size for an iphone to display
I know there is this post , but I still want to know more
I'm making a chat responder for a game and i want know if there
I want to know if there is any free tool to test the performance

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.