﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-随意飘荡-最新评论</title><link>http://www.cppblog.com/guanghong/CommentsRSS.aspx</link><description /><language>zh-cn</language><pubDate>Mon, 12 May 2008 06:19:18 GMT</pubDate><lastBuildDate>Mon, 12 May 2008 06:19:18 GMT</lastBuildDate><generator>cnblogs</generator><item><title>re: LPVOID,static_cast 的问题</title><link>http://www.cppblog.com/guanghong/archive/2008/05/13/49629.html#49697</link><dc:creator>Guanghong(随意飘荡)</dc:creator><author>Guanghong(随意飘荡)</author><pubDate>Tue, 13 May 2008 01:25:00 GMT</pubDate><guid>http://www.cppblog.com/guanghong/archive/2008/05/13/49629.html#49697</guid><description><![CDATA[嗯，谢谢“啸天猪”^_^<br>是我的思路有问题！转换成void*之后，多态的信息就丢失了<img src ="http://www.cppblog.com/guanghong/aggbug/49697.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guanghong/" target="_blank">Guanghong(随意飘荡)</a> 2008-05-13 09:25 <a href="http://www.cppblog.com/guanghong/archive/2008/05/13/49629.html#49697#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: LPVOID,static_cast 的问题</title><link>http://www.cppblog.com/guanghong/archive/2008/05/12/49629.html#49646</link><dc:creator>啸天猪</dc:creator><author>啸天猪</author><pubDate>Mon, 12 May 2008 09:16:00 GMT</pubDate><guid>http://www.cppblog.com/guanghong/archive/2008/05/12/49629.html#49646</guid><description><![CDATA[使用强制转换尤其是void * 就意味着你在C++的类型检查系统上开了一个缺口，所以你得自己负责所有的后果。<br><br>Derived有两个基类，所以它的对象中会包含2个Vptr，而你使用的编译器在实现中应该是将第一个基类的Vptr放在对象的起始处，这样（void *） &amp;a 与statci_cast&lt;Base1 *&gt;(&amp;a) 在数值上相同的;另一方面，(void *) &amp;a 与static_cast&lt;Base2 *&gt;(&amp;a)在数值上是不同的，后者会根据Derived和Base2之间的关系对指针值进行调整，以保证它指向正确的Vptr，即基类Base2对应的Vptr。<br><br>程序中的3处在使用static_cast之前先执行了void *强制转换，这样类型信息就丢失了，因而static_cast&lt;Base2 *&gt; ( (void *) &amp;a)得到的结果指向基类Base1对应的vptr，而不是基类Base2对应的vptr<br><br>“计算Derived中基类的偏移”这样的事情是和编译器实现紧密相关的，不具备可移植性，我觉得你不该采用这样的解决思路。<img src ="http://www.cppblog.com/guanghong/aggbug/49646.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guanghong/" target="_blank">啸天猪</a> 2008-05-12 17:16 <a href="http://www.cppblog.com/guanghong/archive/2008/05/12/49629.html#49646#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>