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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:09:11+00:00 2026-06-02T05:09:11+00:00

In the common diamond scenario: class MBase { public: MBase(int) {} virtual char const*

  • 0

In the common diamond scenario:

class MBase {
  public:
    MBase(int) {}
    virtual char const* vf() const = 0;
    virtual ~MBase() {}
};

class D1 : public MBase { //NOT VIRTUAL!!!
  public:
    D1() : MBase(1) {}
    char const* vf() const { return "D1"; }
};

class D2 : virtual public MBase {
  public:
    D2() : MBase(2) {}
    char const* vf() const { return "D2"; }
};

class Bottom : public D1, public D2 {
  public:
    char const* vf() const { return "Bottom"; }
}

What would change if I modified the inheritance modifier of Bottom to be virtual for both D1 and D2? I mean, would that make any impact:

class Bottom : public virtual D1, public virtual D2 {
  public:
    char const* vf() const { return "Bottom"; }
}
  • 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-02T05:09:12+00:00Added an answer on June 2, 2026 at 5:09 am

    No it doesn’t. Each class chooses which of its direct base classes may be shared with others. Since Bottom is a leaf in your implementation and it has in both cases only one instance of D1 and D2, it will in both cases have exactly one nested object of these types. Since D1 refuses to share an MBase, Bottom will have two MBase objects nested in it as well.

    However MBase is not directly accessible from both versions of Bottom since it is ambiguous. You would have to explicitly cast to D1 or D2 in order to access MBase through Bottom objects (precisely because there are two MBases).


    The difference would be if you had one D1 that virtually inherits from MBase and one that doesn’t.

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

Sidebar

Related Questions

Common scenario: I have a library that uses other libraries. For example, a math
Most common ORMs implement persistence by reachability, either as the default object graph change
Many common filesystems do not offer atomic operations, yet writing files in an atomic
A common scenario in my code is that I got a functor that is
Common scenario - Activity with a background Service to poll server. The Service will
How common usage are Page Methods in ASP.NET 4? I would like an example
Common scenario: Hierachical domain model is being mapped to flat view model for presentation
A common pattern in C++ is to create a class that wraps a lock
A common scenario when using source control is to have a development branch along
C++: I have a base class A with a pure virtual function f() and

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.