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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:07:07+00:00 2026-05-29T15:07:07+00:00

First off I apologize if there is another post out there that answers this,

  • 0

First off I apologize if there is another post out there that answers this, all the similar posts I found dealt with diamond inheritance schemes or defined functions, which this does not.

In short, I’m wondering if it is possible to have one class inherit from two other classes where both child classes has a function with the same name and arguments but it is defined in one child class, and pure-virtual in another. Furthermore if I can do this, would invoking the function on the pure-virtual/abstract class end up calling the defined function on the other child class with minimal changes to the derived class?

Example:

class A
{
    public:
    virtual void Set(int X) = 0;
};

class B
{
    public:
    virtual void Set(int X);
};

class AB : public A, public B
{
    //other methods not relevant to example go here
};

int main(int argc, char **argv)
{
    int Y = 5;
    A* ObjectA = new AB();
    ObjectA->Set(Y);
    return 0;
}

So far my attempts to compile this basic example have been met with errors that say:

‘AB’ : cannot instantiate abstract class
due to following members:
‘void A::Set(int)’ : is abstract

When doing my own research I couldn’t find a clear answer, but based on other questions that dealt with related topics I found that using a “using B::Set” in class AB may help with this. But when I try adding it to the AB class definition, the error persists.

Is there any way I can make this work?

  • 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-29T15:07:08+00:00Added an answer on May 29, 2026 at 3:07 pm

    Have you tried implementing the method:

    class AB : public A, public B
    {
        void Set(int X) {}
    };
    

    The reason it’s not working is that A::Set() is pure virtual. I.e. it has no implementation. But you try to call it. You have to override it in the derived class in order to be able to instantiate the derived class.

    The using doesn’t work in your case because you have an A*, so there’s no ambiguity for the compiler.

    In case you had:

    AB* ObjectA = new AB();
    ObjectA->Set(Y);
    

    you’d have to use using inside the declaration of AB to resolve the ambiguity.

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

Sidebar

Related Questions

First of all I apologize in advance for this question, a bit off the
First off I would like to apologize beforehand, in case this turns out to
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS
First off, there's a bit of background to this issue available on my blog:
First off, let me apologize if this has been asked already, but I can’t
First off I want to say that I wasn't really sure where to post
First off, I want to apologize beforehand, as I know there is a lot
First off, I'd like to apologize in advance for not knowing this. I've been
First off, I apologize if this is a confusing or backwards way to go
First off, I apologize if it's considered poor etiquette to cross-post on stackexchange sites,

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.