内存布局在嵌套类和C ++中的多继承之间的区别? [英] Memory Layout difference between nested classes and multiple inheritance in C++?

查看:146
本文介绍了内存布局在嵌套类和C ++中的多继承之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解COM如何指定其对象的布局,以便想要使用COM对象的客户端知道如何做。



我已经读过一个实现多个接口的COM对象可以用不同的方式来实现它,包括使用嵌套类或多重继承。



我的理解是,两种技术都必须产生相同的内存布局(符合COM规范),以便客户端想要使用COM对象



所以我的具体问题是:使用多继承和嵌套类实现的c ++对象的内存布局是有区别的。 / p>

有人能指出我指定COM对象布局的位置吗?

解决方案

COM完全与对象的内存布局无关。所有它想要和需要的是一个函数指针表,当它调用 IUnknown :: QueryInterface()。你如何实现它完全取决于你。 MFC使用嵌套类,几乎任何事情都利用了对C ++编译器中的多重继承的内置支持。 MSVC ++编译器实现它的方式与COM需要的完全兼容。这不是意外。使用你看到的关于COM的书中列出的样板代码,显示如何正确实现IUnknown。


I am trying to understand how COM specifies the layout of its objects so that a client that wants to use a COM object knows how to do it.

I've read that a COM object that implements multiple interfaces can do it it in different ways including using nested classes or multiple inheritance.

My understanding is that both techniques would have to produce the same memory layout (conforming to the COM spec) so that a client that wants to use the COM object (for example in C), knows how to do it.

So my specific question is: is there a difference in memory layout for c++ objects implemented using multiple inheritance versus nested classes.

And could somebody point me to where a COM object layout is specified?

解决方案

COM is completely agnostic of the memory layout of your object. All that it 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, just about anything else leverages the built-in support for multiple inheritance in the C++ compiler. The way the MSVC++ compiler implements it is completely compatible with what COM needs. This is no accident. Use the boilerplate code you see listed in books about COM that shows how to properly implement IUnknown.

这篇关于内存布局在嵌套类和C ++中的多继承之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆