⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 [c++对象模型][8]多重继承与虚函数表 - itech's blog - 博客园.htm

📁 最为全面的c++内存模型探秘。不管是初学者还是老手
💻 HTM
📖 第 1 页 / 共 5 页
字号:
style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN 
style="COLOR: #800000">B2:</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #000000">&lt;&lt;</SPAN><SPAN 
style="COLOR: #000000">&nbsp;pB2&nbsp;</SPAN><SPAN 
style="COLOR: #000000">&lt;&lt;</SPAN><SPAN 
style="COLOR: #000000">&nbsp;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;B3&nbsp;</SPAN><SPAN 
style="COLOR: #000000">*</SPAN><SPAN 
style="COLOR: #000000">pB3&nbsp;</SPAN><SPAN 
style="COLOR: #000000">=</SPAN><SPAN 
style="COLOR: #000000">&nbsp;dynamic_cast</SPAN><SPAN 
style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">B3</SPAN><SPAN 
style="COLOR: #000000">*&gt;</SPAN><SPAN 
style="COLOR: #000000">(pB1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout&nbsp;</SPAN><SPAN 
style="COLOR: #000000">&lt;&lt;</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN 
style="COLOR: #800000">B3:</SPAN><SPAN style="COLOR: #800000">"</SPAN><SPAN 
style="COLOR: #000000">&nbsp;</SPAN><SPAN 
style="COLOR: #000000">&lt;&lt;</SPAN><SPAN 
style="COLOR: #000000">&nbsp;pB3&nbsp;</SPAN><SPAN 
style="COLOR: #000000">&lt;&lt;</SPAN><SPAN 
style="COLOR: #000000">&nbsp;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;delete&nbsp;pD;<BR>}</SPAN></SPAN></DIV>
<P>&nbsp;</P>
<P>2)验证代码的运行结果:</P>
<P><IMG 
src="[C++对象模型][8]多重继承与虚函数表 - iTech's Blog - 博客园.files/2009022810164625.png"></P>
<P>&nbsp;</P>
<P>3)总结:</P>
<P><SPAN 
style="COLOR: #ff0000">从多重继承的内存布局,我们可以看到子类新加入的虚函数被加到了第一个基类的虚函数表,所以当dynamic_cast的时候,子类和第一个基类的地址相同,不需要移动指针,但是当dynamic_cast到其他的父类的时候,需要做相应的指针的移动。</SPAN></P>
<P>三 完!</P>
<DIV id=MySignature>
<P>感谢,Thanks!<BR><BR>作者:<A href="http://itech.cnblogs.com/">iTech</A><BR>出处:<A 
href="http://itech.cnblogs.com/">http://itech.cnblogs.com/</A> 
<BR>转载:本文版权归作者iTech所有,转载请注明出处,不得用于商业用途!</P></DIV>
<DIV id=EntryTag>Tag标签: <A 
href="http://www.cnblogs.com/itech/tag/[Cpp对象模型]/">[Cpp对象模型]</A></DIV></DIV>
<DIV class=postDesc>posted @ 2009-02-28 10:21 <A 
href="http://www.cnblogs.com/itech/">iTech</A> 阅读(56) <A 
href="http://www.cnblogs.com/itech/archive/2009/02/28/1399995.html#Post">评论(0)</A> 
&nbsp;<A 
href="http://www.cnblogs.com/itech/admin/EditPosts.aspx?postid=1399995">编辑</A> 
<A href="http://www.cnblogs.com/itech/AddToFavorite.aspx?id=1399995">收藏</A> <A 
onclick="PutInWz();return false;" 
href="http://www.cnblogs.com/itech/archive/2009/02/28/1399995.html#">网摘</A> 
所属分类: <A href="http://www.cnblogs.com/itech/category/170009.html">C++</A> 
</DIV></DIV><IMG height=1 
src="[C++对象模型][8]多重继承与虚函数表 - iTech's Blog - 博客园.files/1399995.jpg" width=1> <!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="http://www.cnblogs.com/itech/archive/2009/02/28/1399995.html"
dc:identifier="http://www.cnblogs.com/itech/archive/2009/02/28/1399995.html"
dc:title=""
trackback:ping="http://www.cnblogs.com/itech/services/trackbacks/1399995.aspx" />
</rdf:RDF>
--></DIV><!--end: topics 文章、评论容器-->
<DIV id=AjaxHolder_UpdatePanel1>
<STYLE>TD {
	FONT-SIZE: 12px
}
.commentTextBox {
	FONT-SIZE: 13px; FONT-FAMILY: Verdana
}
A.blue:visited {
	COLOR: blue
}
A.blue:active {
	COLOR: blue
}
A.blue:link {
	COLOR: blue
}
A.blue:hover {
	COLOR: blue
}
</STYLE>
<!--Beging Temp Save-->
<STYLE>.userData {
	BEHAVIOR: url(#default#userdata)
}
</STYLE>

<DIV class=userData id=CommentsPersistDiv></DIV>
<SCRIPT type=text/javascript>
    function pageLoad() {
        Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(handleInitializeRequest);
        //Sys.WebForms.PageRequestManager.getInstance().add_endRequest(handleEndRequest);
    }

    function handleInitializeRequest(sender, args) {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        var eid = args.get_postBackElement().id;
        /*if (eid.indexOf("DeleteLink")>0) 
        {
        args.get_postBackElement().innerHTML = "<font color='red'>正在删除...</font>";         
        }    
        else */
        if (eid.indexOf("btnSubmit") > 0) {
            document.getElementById("AjaxHolder_PostComment_ltSubmitMsg").innerHTML = "正在提交...";
            document.getElementById("AjaxHolder_PostComment_btnSubmit").disabled = true;
        }
        else if (eid.indexOf("refreshList") > 0) {
            document.getElementById("AjaxHolder_PostComment_refreshList").innerHTML = "<font color='red'>正在刷新...</font>";
        }

    }

    function TempSave(ElementID) {
        try {
            CommentsPersistDiv.setAttribute("CommentContent", document.getElementById(ElementID).value);
            CommentsPersistDiv.save("CommentXMLStore");
        }
        catch (ex) {
        }

    }
    function Restore(ElementID) {
        CommentsPersistDiv.load("CommentXMLStore");
        document.getElementById(ElementID).value = CommentsPersistDiv.getAttribute("CommentContent");
    }	
			
			
</SCRIPT>
<!--Ene TempSave-->
<DIV id=divRefreshComments 
style="FONT-SIZE: 12px; MARGIN-BOTTOM: 5px; MARGIN-RIGHT: 10px; TEXT-ALIGN: right"><A 
id=AjaxHolder_PostComment_refreshList 
href="javascript:__doPostBack('AjaxHolder$PostComment$refreshList','')">刷新评论列表</A>&nbsp;&nbsp;</DIV>
<DIV class=commentform><SPAN id=AjaxHolder_PostComment_ltSubmitMsg 
style="COLOR: red"></SPAN><BR><A name=Feedback></A>
<TABLE style="WIDTH: 600px" cellSpacing=1 cellPadding=1 border=0>
  <TBODY>
  <TR>
    <TD colSpan=3>
      <DIV id=AjaxHolder_PostComment_panelADUper></DIV></TD></TR>
  <TR>
    <TD></TD>
    <TD></TD>
    <TD></TD></TR>
  <TR>
    <TD width=55>姓名 </TD>
    <TD colSpan=2><INPUT class=tb_comment_name 
      id=AjaxHolder_PostComment_tbName name=AjaxHolder$PostComment$tbName> <A 
      href="http://passport.cnblogs.com/login.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fitech%2farchive%2f2009%2f02%2f28%2f1399995.html">[登录]</A> 
      <A 
      href="http://passport.cnblogs.com/register.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fitech%2farchive%2f2009%2f02%2f28%2f1399995.html%23Top">[注册]</A><SPAN 
      id=AjaxHolder_PostComment_RequiredFieldValidator2 
      style="VISIBILITY: hidden; COLOR: red">请输入你的姓名</SPAN> </TD></TR>
  <TR>
    <TD>主页 </TD>
    <TD><INPUT class=commenttb id=AjaxHolder_PostComment_tbUrl 
      name=AjaxHolder$PostComment$tbUrl> </TD>
    <TD></TD></TR>
  <TR id=AjaxHolder_PostComment_trEmail>
    <TD>Email </TD>
    <TD colSpan=2><INPUT class=commenttb id=AjaxHolder_PostComment_tbEmail 
      name=AjaxHolder$PostComment$tbEmail>(仅博主可见)<SPAN 
      id=AjaxHolder_PostComment_revContactMail 
      style="VISIBILITY: hidden; COLOR: red">邮件地址无效</SPAN> </TD></TR>
  <TR>
    <TD align=left colSpan=3>
      <TABLE class=CommentForm id=AjaxHolder_PostComment_tbCaptchaImage 
      cellSpacing=0 cellPadding=0 border=0>
        <TBODY>
        <TR>
          <TD colSpan=3><SPAN 
            id=AjaxHolder_PostComment_Requiredfieldvalidator4 
            style="DISPLAY: none; COLOR: red">请输入验证码</SPAN> <SPAN 
            id=AjaxHolder_PostComment_lblImage 
            style="FONT-WEIGHT: bold; COLOR: red"></SPAN></TD></TR>
        <TR>
          <TD>验证码 </TD>
          <TD colSpan=2><INPUT id=AjaxHolder_PostComment_CodeNumberTextBox 
            style="WIDTH: 100px" 
            name=AjaxHolder$PostComment$CodeNumberTextBox>*&nbsp;&nbsp;<IMG 
            alt=验证码 
            src="[C++对象模型][8]多重继承与虚函数表 - iTech's Blog - 博客园.files/JpegImage.jpg" 
            align=absMiddle><A id=AjaxHolder_PostComment_lkbChangeCode 
            href="javascript:__doPostBack('AjaxHolder$PostComment$lkbChangeCode','')">看不清,换一张</A> 
          </TD></TR></TBODY></TABLE></TD></TR>
  <TR>
    <TD style="TEXT-ALIGN: left" colSpan=3>
      <DIV style="WIDTH: 600px">
      <DIV class=divPostCommentBox>内容(请不要发表任何与政治相关的内容) <SPAN 
      id=AjaxHolder_PostComment_RequiredFieldValidator3 
      style="VISIBILITY: hidden; COLOR: red">请输入评论内容</SPAN><BR><TEXTAREA class=commentTextBox id=AjaxHolder_PostComment_tbComment onkeydown="ctlent(event,'AjaxHolder_PostComment_tbComment')" name=AjaxHolder$PostComment$tbComment></TEXTAREA> 
      </DIV>
      <DIV class=CommentBoxNav><A tabIndex=-1 href="http://www.cnblogs.com/" 
      target=_blank>网站首页</A><BR><BR><A tabIndex=-1 
      href="http://news.cnblogs.com/" target=_blank>新闻频道</A><BR><BR><A 
      tabIndex=-1 href="http://space.cnblogs.com/" 
      target=_blank>社区</A><BR><BR><A tabIndex=-1 
      href="http://space.cnblogs.com/group.htm" target=_blank>小组</A><BR><BR><A 
      tabIndex=-1 href="http://space.cnblogs.com/q" 
      target=_blank>博问</A><BR><BR><A tabIndex=-1 href="http://wz.cnblogs.com/" 
      target=_blank>网摘</A><BR><BR><A tabIndex=-1 href="http://job.cnblogs.com/" 
      target=_blank>人才</A><BR><BR><A tabIndex=-1 href="http://zzk.cnblogs.com/" 
      target=_blank>找找看</A><BR><BR></DIV></DIV></TD></TR>
  <TR>
    <TD colSpan=3><SPAN id=AjaxHolder_PostComment_Message 
      style="COLOR: red"></SPAN></TD></TR>
  <TR>
    <TD colSpan=3><INPUT id=AjaxHolder_PostComment_chkRemember tabIndex=-1 
      type=checkbox CHECKED name=AjaxHolder$PostComment$chkRemember><LABEL 
      for=AjaxHolder_PostComment_chkRemember>Remember Me?</LABEL> </TD></TR>
  <TR>
    <TD height=23><INPUT class=commentButton id=AjaxHolder_PostComment_btnSubmit onclick="TempSave('AjaxHolder_PostComment_tbComment');WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;AjaxHolder$PostComment$btnSubmit&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" type=submit value=提交 name=AjaxHolder$PostComment$btnSubmit> 
    </TD>
    <TD colSpan=2 height=23>&nbsp; <A id=AjaxHolder_PostComment_lnkLogin 
      href="http://passport.cnblogs.com/login.aspx?ReturnURL=http%3a%2f%2fwww.cnblogs.com%2fitech%2farchive%2f2009%2f02%2f28%2f1399995.html">登录</A>&nbsp;&nbsp;<A 
      id=AjaxHolder_PostComment_linkLoginComment 
      onclick="if(document.getElementById('AjaxHolder_PostComment_tbComment').value != '') return confirm('未提交的评论内容将会丢失, 你真的要进入高级评论吗?');" 
      href="http://www.cnblogs.com/itech/archive/2009/02/28/1399995.html?login=1#Post">使用高级评论</A>&nbsp;&nbsp; 
      <A 
      href="http://passport.cnblogs.com/register.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2fitech%2farchive%2f2009%2f02%2f28%2f1399995.html%23Bottom">新用户注册</A>&nbsp;&nbsp; 
      <A 
      href="http://www.cnblogs.com/itech/archive/2009/02/28/1399995.html#Top">返回页首</A>&nbsp;&nbsp;<A 
      id=AjaxHolder_PostComment_lbRestore 
      onclick="Restore('AjaxHolder_PostComment_tbComment'); return false;" 
      href="http://www.cnblogs.com/itech/archive/2009/02/28/1399995.html#Post">恢复上次提交</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    </TD></TR>
  <TR>
    <TD colSpan=3><LABEL class=CtrlEnter>[使用Ctrl+Enter键可以直接提交]</LABEL> </TD></TR>
  <TR>
    <TD colSpan=3>该文被作者在 2009-03-01 19:33 编辑过 </TD></TR>
  <TR>
    <TD colSpan=3></TD></TR>
  <TR>
    <TD colSpan=3><A href="http://a4.yeshj.com/rd/24287/" target=_blank><SPAN 
      style="COLOR: red">IT“暖冬”计划紧急招募中</SPAN></A><BR><SPAN 
      style="COLOR: red">推荐职位:</SPAN><A href="http://job.cnblogs.com/offer/510/" 
      target=_blank><SPAN style="COLOR: red">.NET开发工程师</SPAN></A>&nbsp;&nbsp; <A 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -