Difference in memory layout between nested classes and multiple inheritance in C ++?

I am trying to understand how COM points out the layout of its objects so that the client who wants to use the COM object knows how to do this.

I read that a COM object that implements several interfaces can do this in different ways, including using nested classes or multiple inheritance.

I understand that both methods would have to create the same memory layout (corresponding to the COM specification) so that a client who wants to use a COM object (for example, in C) knows how to do this.

So, my specific question is: is there a difference in the memory layout for C ++ objects implemented using multiple inheritance compared to nested classes.

And can someone tell me where the layout of the COM object is indicated?

+3
source share
4 answers

COM is completely agnostic of the memory layout of your object. All he wants and needs is a table of function pointers when it calls IUnknown::QueryInterface(). How you implement it is completely up to you. MFC uses nested classes, almost anything uses the built-in support for multiple inheritance in the C ++ compiler. The implementation method of the MSVC ++ compiler is fully compatible with what COM requires. This is no coincidence. Use the template code that you see in books about COM that shows how to implement IUnknown correctly.

+8
source

"", COM, vtable ( ), . IUnknown, , , QueryInterface .

. , COM OO: , COM-, - QueryInterface IUnknown - , , .

:

  • , , COM- , : / .
  • COM .
+5

, COM- , . , - , .

, . , , . vtables, , , - , - .

, . , ! , (vtables) , . , , .

+1

, , , .

0

Source: https://habr.com/ru/post/1783723/


All Articles