[cpp] Re: 深度探索c++对象模型

Liu.WeiPeng pongba at gmail.com
Sat Feb 3 13:48:56 CST 2007


> 最近在看侯捷的深度探索c++对象模型。
> 在第三章3.4节(116页多重继承情况下的data布局)中的一段话不是太明白,
> 下面列出这段话,"某些编译器(例如metaware)设计有一种优化技术,只要第二个(或后继)
> base class声明了一个virtual function,而第一个base class没有,就把多个
> base classes的次序进行调换。这样可以在derived class object中至少产生
> 一个vptr。这项优化技术并未得到全球各厂商的认可,因此并不普及。"
>
> 我不明白的是为什么调换次序就会少产生一个vptr呢?
> 请大家指教。谢谢。
>
>
The reason is that if we swap the two base-classes, then the one with
virtual functions(i.e. originally the second one) would be able to share a
vptr with the derived class.
Otherwise, we'd have to generate two vptrs, one for the derived class, and
the other for the second  base-class; and between the two vptrs are the
data-members, if any, of the first base-class.

-- 
The Louvre of C++
http://blog.csdn.net/pongba
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codingnow.com/pipermail/cpp/attachments/20070203/50bf7532/attachment.html


More information about the Cpp mailing list