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

The Archive Base Latest Questions

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

Is it possible to implement an abstract base class with members inherited from another

  • 0

Is it possible to implement an abstract base class with members inherited from another parent class in C++?

It works in C#, so I tried doing it in C++:

// Virtual destructors omitted for brevity

class ITalk
{
public:
    virtual void SayHi() = 0;
};

class Parent
{
public:
    void SayHi();
};

class Child : public Parent, public ITalk
{
};

void Parent::SayHi()
{
    std::printf("Hi\n");
}

My compiler didn’t really like it though:

ITalk* lChild = new Child(); // You idiot, Child is an abstract class!
lChild->SayHi();

I can’t add public ITalk to the Parent class because “base-class ‘ITalk’ is already a base-class of ‘Parent’.” I could move public ITalk up to the Parent class, but in my particular scenario that complicates a lot of things.

  • 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-24T20:49:44+00:00Added an answer on May 24, 2026 at 8:49 pm

    No because what you really have is two base classes without any knowledge of each other.

    Italk    Parent
     / \       / \
      |         |
      +---------+
           |
         Child
    

    If Parent and Italk had two variables named i, there’d be two instances of “i”, ITalk::i and Parent::i. To access them you’d have to fully qualify which one you wanted.

    The same is true of methods, lChild has two methods called SayHi and you need to clarify which one you mean when calling SayHi because the multiple inheritance has made it ambiguous.

    You have Parent’s SayHi

    lChild->Parent::SayHi();
    

    and Italk’s SayHi:

    lChild->ITalk::SayHi(); 
    

    The latter is pure virtual and because its abstract needs to be overridden locally in Child. To satisfy this you’ll need to define

    Child::SayHi();
    

    Which would now hide Parent::SayHi() when invoking SayHi without scoping it to the class:

    lChild->SayHi() //parent's now hidden, invoke child's
    

    Of course Child::SayHi() could call Parent::SayHi():

    void Child::SayHi()
    {
         Parent::SayHi();
    }
    

    which would solve your problem.

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

Sidebar

Related Questions

Possible Duplicate: Interface vs Base class A class implementing an interface has to implement
In C++, is it possible to have a base plus derived class implement a
Is it possible to let the IDE automatically implement inherited abstract methods in Delphi
Possible Duplicates: Interface vs Base class Interface or abstract class? Hi All, I am
Is it possible to have a abstract base class with a number of pure
In C++ is it possible to use another base class to provide the implementation
Is it possible to implement batching of multiple stored procedure calls (doing updates/deletes) in
I have an abstract immutable base class that defines enforces child classes to be
Possible Duplicates: Abstract classes vs Interfaces Abstract class and Interface class? Hi All, I
Possible Duplicate: Why can’t I create an abstract constructor on an abstract C# 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.