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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:58:05+00:00 2026-06-07T02:58:05+00:00

Say I have 4 classes: class I { public: virtual void X() = 0;

  • 0

Say I have 4 classes:

class I { public: virtual void X() = 0; };
class A : public virtual I { public: virtual void X() { } };
class B : public I {  };
class C : public A, public B { };

I, B and C are abstract, where as A is not. If I simply add virtual to the inheritance of I for B, then A::X() resolves I::X() in C.

However, I cannot change the source of B.

My question: Can I get A::X() to resolve I::X for C without being able to change B? I have tried declaring A and B to be virtual to C to no avail. I am trying to have no redundant code (e.g. have C declare X() { A::X(); }). Any neat hacks?

Also – there are a few questions very much like this, but I couldn’t find any talking about using virtual inheritance. Please point to me one if I missed it.

  • 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-07T02:58:08+00:00Added an answer on June 7, 2026 at 2:58 am

    This is quite good: When virtual inheritance IS a good design?

    The problem here is that in C you have two interfaces I. That is why A::x() satisfies
    its interface I – but it cannot make not abstract interface I from class B.
    For C the only way to have exactly one interface of I – is to change B to derive from I virtually – in this way both I interfaces from A and from B will be merged to one in C. You cannot change B – so the only way is to add this redundant code which you are trying to avoid. I mean define C::X().

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

Sidebar

Related Questions

Say I have an abstract class class NecessaryDanger { public: virtual void doSomethingDangerous() =0;
I have the following classes: class A { public: virtual void f() {} };
Say I have the following abstract class: class AbstractClass { public: AbstractClass() {} virtual
Background I have an abstract class, something like class IConverter{ public: virtual void DoConvertion()
Lets say I have two classes: public class A { public virtual int Id
Let's say i have 2 classes: class Class1 { public: std::vector<CustomClass3*> mVec; public: Class1();
Let's say we have these two classes: public class Base { public static int
Say you have two classes, order and customer: public class Customer{ public int CustomerId
Lets say i have the following c# classes: abstract class a { protected abstract
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {

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.