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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:38:26+00:00 2026-05-15T14:38:26+00:00

I have read some vague statement that virtual inheritance doesn’t provide the memory structure

  • 0

I have read some vague statement that virtual inheritance doesn’t provide the memory structure required by COM, so we have to use the normal inheritance. Virtual inheritance is invented to handle the diamond problem.

Could someone show me an illustration of the difference of memory structure details between this two inherit approaches? And the key reason why virtual inheritance is not suitable for COM. A picture would be best.

Many thanks.

  • 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-15T14:38:27+00:00Added an answer on May 15, 2026 at 2:38 pm

    COM interfaces are rather like JAVA interfaces in a way – they don’t have data members. This means that interface inheritance is different to class inheritance when multiple inheritance is used.

    To start with, consider non-virtual inheritance with diamond-shaped inheritance patterns…

    • B inherits A
    • C inherits A
    • D inherits B and C

    An instance of D contains two separate instances of the data members of A. That means that when a pointer-to-A points into an instance of D, it needs to identify which instance of A within D it means – the pointer is different in each case, and pointer casts are not simple relabellings of the type – the address changes too.

    Now consider the same diamond with virtual inheritance. Instances of B, C and D all contain a single instance of A. If you think of B and C having a fixed layout (including the A instance) this is a problem. If Bs layout is [A, x] and Cs layout is [A, y], then [B, C, z] is not valid for D – it would contain two instances of A. What you have to use is something like [A, B’, C’, z] where B’ is everything from B except the inherited A etc.

    This means that if you have a pointer-to-B, you don’t have a single scheme for dereferencing the members inherited from A. Finding those members is different depending on whether the pointer points to a pure-B or a B-within-D or a B-within-something-else. The compiler needs some run-time clue (virtual tables) to find the inherited-from-A members. You end up needing several pointers to several virtual tables in the D instance, as theres a vtable for the inherited B and for the inherited C etc, implying some memory overhead.

    Single inheritance doesn’t have these issues. Memory layout of instances is kept simple, and virtual tables are simpler too. That’s why Java disallows multiple inheritance for classes. In interface inheritance there are no data members, so again these problems simply don’t arise – there’s no issue of which-inherited-A-with-D, nor of different ways to find A-within-B depending on what that particular B happens to be within. Both COM and Java can allow multiple inheritance of interfaces without having to handle these complications.

    EDIT

    I forgot to say – without data members, there is no real difference between virtual and non-virtual inheritance. However, with Visual C++, the layout is probably different even if there are no data members – using the same rules for each inheritance style consistently irrespective of whether any data members are present or not.

    Also, the COM memory-layout matches the Visual-C++ layout (for supported inheritance types) because it was designed to do that. There’s no reason why COM couldn’t have been designed to support multiple and virtual inheritance of “interfaces” with data members. Microsoft could have designed COM to support the same inheritance model as C++, but chose not to – and there’s no reason why they should have done otherwise.

    Early COM code was often written in C, meaning hand-written struct layouts that had to precisely match the Visual-C++ layout to work. Layouts for multiple and virtual inheritance – well, I wouldn’t volunteer to do it manually. Besides, COM was always its own thing, meant to link code written in many different languages. It was never intended to be tied to C++.

    YET MORE EDITING

    I realised I missed a key point.

    In COM, the only layout issue that matters is the virtual table, which only has to handle method dispatch. There are significant differences in layout depending on whether you take the virtual or non-virtual approach, similar to the layout of on object with data members…

    • For non-virtual, the D vtab contains an A-within-B vtab and an A-within-C vtab.
    • For virtual, the A only occurs once within Ds vtable, but the object contains multiple vtables and pointer casts need address changes.

    With interface-inheritance, this is basically implementation detail – there’s only one set of method implementations for A.

    In the non-virtual case, the two copies of the A virtual table would be identical (leading to the same method implementations). Its a slightly larger virtual table, but the per-object overhead is less and the pointer casts are just type-relabelling (no address change). It’s simpler and more efficient implementation.

    COM can’t detect the virtual case because there’s no indicator in the object or vtable. Also, there’s no point supporting both conventions when there’s no data members. It just supports the one simple convention.

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

Sidebar

Related Questions

I have read some of the questions and answers here, but it none match
I have read some posts having the same problem. I tried to adapt their
I have read some different responses for this same question, so I dont know
I have read some of the basic Google Apps Script documentation/tutorials. I have not
I have read some posts on here about not mixing parameters when passing into
I have read some posts about this topic and the answers are comet, reverse
I have read some articles on POCO in the enttity framework but still don't
I have read some threads regarding this and I did already take steps to
In the book Linux System Programming I have read some like this: fgetc returns
I have just switched from svn to mercurial and have read some tutorials about

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.