﻿<?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++博客-Ordinary, But Passional</title><link>http://www.cppblog.com/pxhszcn/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 16 Mar 2010 10:39:04 GMT</lastBuildDate><pubDate>Tue, 16 Mar 2010 10:39:04 GMT</pubDate><ttl>60</ttl><item><title>俄罗斯方块Tigerkin Tetris 1.0</title><link>http://www.cppblog.com/pxhszcn/archive/2008/11/17/67081.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Sun, 16 Nov 2008 16:59:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/11/17/67081.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/67081.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/11/17/67081.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/67081.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/67081.html</trackback:ping><description><![CDATA[<p>写了个俄罗斯方块，逻辑算法部分中规中矩，棋盘主要采用二维数组的数据结构，而每种方块样式都是Block类的一个对象，方便扩充；界面部分采用了DialogBox，用GDI画，同时还使用双缓冲技术防止画面闪烁。考虑到可以在RC文件里设计程序界面，所以采用了Dialogbox作为主界面，于是麻烦便来了：DialogBox无法接受WM_KEYDOWN中的VK_UP，VK_DOWN等，也就是说上下左右按键没法用。。试了几种办法，都不行，干脆换成了home，end，page up，page down键。玩的时候很不方便~等我再查查资料再改吧，先把这个有残缺的1.0版本发上来。</p>
<p>程序截图：<a href="http://www.cppblog.com/images/cppblog_com/pxhszcn/WindowsLiveWriter/TigerkinTetris1.0_93F/tetris.jpg"><img style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=tetris border=0 alt=tetris src="http://www.cppblog.com/images/cppblog_com/pxhszcn/WindowsLiveWriter/TigerkinTetris1.0_93F/tetris_thumb.jpg" width=367 height=463></a> </p>
<p>下载地址：<a href="http://www.cppblog.com/Files/pxhszcn/Tigerkin%20Tetris%201.0(exe).rar">可执行文件</a>，<a href="http://www.cppblog.com/Files/pxhszcn/Tigerkin%20Tetris%201.0.rar">源代码</a></p>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/67081.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-11-17 00:59 <a href="http://www.cppblog.com/pxhszcn/archive/2008/11/17/67081.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>比较一下Live Search 和Google</title><link>http://www.cppblog.com/pxhszcn/archive/2008/08/16/59048.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Sat, 16 Aug 2008 04:23:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/08/16/59048.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59048.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/08/16/59048.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59048.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59048.html</trackback:ping><description><![CDATA[<p>我要在MSDN里搜Windows API DrawText函数，如图：</p>
<p><img border=0 alt="" src="http://images.cnblogs.com/cnblogs_com/pxhszcn/google.JPG" width=563 height=209></p>
<p>Google： 第一条就是。</p>
<p><img border=0 alt="" src="http://images.cnblogs.com/cnblogs_com/pxhszcn/live.JPG" width=575 height=505></p>
<p>Live Search: &nbsp;找了半天没找到</p>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59048.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-08-16 12:23 <a href="http://www.cppblog.com/pxhszcn/archive/2008/08/16/59048.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【封装Windows API系列】—— 1. 消息机制的处理</title><link>http://www.cppblog.com/pxhszcn/archive/2008/08/16/59041.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Sat, 16 Aug 2008 03:45:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/08/16/59041.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59041.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/08/16/59041.html#Feedback</comments><slash:comments>18</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59041.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59041.html</trackback:ping><description><![CDATA[<p>以往写Windows程序，用的较多的是Delphi的VCL，MFC用的很少，总觉得不习惯，相比MFC我倒宁愿用清新简单的Windows API。呵呵。于是乎，我萌生了一个想法，自己来封装Windows API。开始动手。。</p>
<p>首先我找了一个比较简单的Window API程序，试着把他转换成面向对象的形式。程序尽管简单，但刚上来一个棘手的问题就出现了。。消息机制的封装。</p>
<p>我们都知道，Windows中比如点击按钮，移动窗口等等的交互操作都是由消息机制来完成的。每做一个动作，例如点击一个按钮，Windows便会产生一个相应的消息，在这里就是BN_CLICKED，假设点击按钮后会弹出一个窗口，里面显示若干文字，而这些点击按钮后产生的效果就需要由我们程序员来编写。体现在Windows API中便是&#8220;消息处理函数&#8221;，如下：</p>
<p>&nbsp;</p>
<div class=cnblogs_code><span style="COLOR: #000000">LRESULT&nbsp;CALLBACK&nbsp;WndProc&nbsp;(HWND&nbsp;hwnd,&nbsp;UINT&nbsp;message,&nbsp;WPARAM&nbsp;wParam,&nbsp;LPARAM&nbsp;lParam)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">&nbsp;(message)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">&nbsp;BN_CLICKED:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">相关代码<img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">&nbsp;;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">&nbsp;WM_DESTROY:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PostQuitMessage&nbsp;(</span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">)&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;DefWindowProc&nbsp;(hwnd,&nbsp;message,&nbsp;wParam,&nbsp;lParam)&nbsp;;<br>}</span></div>
<p>&nbsp;</p>
<p>每次都要写这么多case的确是挺麻烦的，于是我想用面向对象的方法解决他。</p>
<p>&nbsp;</p>
<div class=cnblogs_code><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;MessageMap<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;消息映射的数目</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Message</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;message[</span><span style="COLOR: #800080">10</span><span style="COLOR: #000000">];&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;可以存放10对消息映射</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;template&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">typename&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Add(MessageType&nbsp;消息名称,&nbsp;T</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;对应的处理函数);&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;增加一对消息映射</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">};<br><br>template&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">typename&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Message<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageType&nbsp;消息名称;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;对应的处理函数;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Run()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;对应的处理函数();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>};<br><br></span><span style="COLOR: #0000ff">enum</span><span style="COLOR: #000000">&nbsp;MessageType{<img alt="" src="http://www.cnblogs.com/Images/dot.gif">}<br><br></span></div>
<p>&nbsp;</p>
<p>这样做其实是有问题的，请看这一段：</p>
<p>&nbsp;</p>
<div class=cnblogs_code><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;MessageMap<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img alt="" src="http://www.cnblogs.com/Images/dot.gif"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Message</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;message[</span><span style="COLOR: #800080">10</span><span style="COLOR: #000000">];&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;由于Message是模板类，这里应该提供模板参数。这样就失去了模板的作用。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;我们使用模板就是为了能让他存储不同的函数指针。</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img alt="" src="http://www.cnblogs.com/Images/dot.gif"><br>};</span></div>
<p>&nbsp;</p>
<p>想一想，如何用一个统一的接口来调用不同的函数？对了，那就是多态。</p>
<p>我们可以增加一个抽象的接口类来提供调用接口，而具体实现的类则由他派生。</p>
<p>&nbsp;</p>
<div class=cnblogs_code><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;MessageInterface<br><img id=Codehighlighter1_23_110_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_23_110_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_23_110_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_23_110_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_23_110_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_23_110_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_23_110_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_23_110_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_23_110_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_23_110_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;MessageType&nbsp;type;<br><img id=Codehighlighter1_81_83_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_81_83_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_81_83_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_81_83_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_81_83_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_81_83_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_81_83_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_81_83_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">MessageInterface()&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_81_83_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_81_83_Open_Text><span style="COLOR: #000000">{}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Run()&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif">template&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">typename&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Message&nbsp;:&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;MessageInterface<br><img id=Codehighlighter1_175_450_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_175_450_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_175_450_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_175_450_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_175_450_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_175_450_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_175_450_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_175_450_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_175_450_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_175_450_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;T</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;classPtr;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;(T::</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;funcPtr)();<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;Message(MessageType&nbsp;_type,&nbsp;T</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;_classPtr,&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;(T::</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;_funcPtr)())&nbsp;:&nbsp;classPtr(_classPtr),&nbsp;funcPtr(_funcPtr)<br><img id=Codehighlighter1_331_351_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_331_351_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_331_351_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_331_351_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_331_351_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_331_351_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_331_351_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_331_351_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_331_351_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_331_351_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;_type;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Run()<br><img id=Codehighlighter1_373_447_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_373_447_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_373_447_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_373_447_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_373_447_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_373_447_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_373_447_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_373_447_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_373_447_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_373_447_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(classPtr)<br><img id=Codehighlighter1_393_444_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_393_444_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_393_444_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_393_444_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_393_444_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_393_444_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_393_444_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_393_444_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_393_444_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_393_444_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(classPtr</span><span style="COLOR: #000000">-&gt;*</span><span style="COLOR: #000000">funcPtr)();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;注意调用函数指针时括号的用法</span><span style="COLOR: #008000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;MessageMap<br><img id=Codehighlighter1_470_806_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_470_806_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_470_806_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_470_806_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_470_806_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_470_806_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_470_806_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_470_806_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_470_806_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_470_806_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;count;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;MessageMap()<br><img id=Codehighlighter1_507_571_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_507_571_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_507_571_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_507_571_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_507_571_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_507_571_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_507_571_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_507_571_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_507_571_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_507_571_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add(DESTROY,&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">MessageMap::OnDestroy);&nbsp;<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;MessageInterface</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;message[</span><span style="COLOR: #800080">10</span><span style="COLOR: #000000">];<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;OnDestroy()<br><img id=Codehighlighter1_623_649_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_623_649_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_623_649_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_623_649_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_623_649_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_623_649_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_623_649_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_623_649_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_623_649_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_623_649_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PostQuitMessage(</span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">);<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;template&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">typename&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Add(MessageType&nbsp;type,&nbsp;T</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;classPtr,&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;(T::</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;funcPtr)())<br><img id=Codehighlighter1_738_804_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_738_804_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_738_804_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_738_804_Closed_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_738_804_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_738_804_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_738_804_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_738_804_Open_Text').style.display='inline';" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_738_804_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_738_804_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message[count</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">]&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Message</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">(type,&nbsp;classPtr,&nbsp;funcPtr);<br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;</span></div>
<p>&nbsp;</p>
<p>问题解决了！哈哈，测试成功！</p>
<p>具体的代码在<a href="http://www.cppblog.com/Files/pxhszcn/test.rar">这里</a>，结构什么的还很不完善，仅仅是处理了消息机制而已，当作演示吧。</p>
<p>&nbsp;</p>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59041.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-08-16 11:45 <a href="http://www.cppblog.com/pxhszcn/archive/2008/08/16/59041.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对C#中事件的一些想法和疑问</title><link>http://www.cppblog.com/pxhszcn/archive/2008/08/07/59016.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Thu, 07 Aug 2008 11:22:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/08/07/59016.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59016.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/08/07/59016.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59016.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59016.html</trackback:ping><description><![CDATA[<p>今天接到leader布置的一个任务，从TextBox继承一个新的控件并为其增加一些功能，其中一个功能如下：</p>
<p><span style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">Add a property: FormatString, when the text box lost focus, the content will be replace with string.Format(FormatString, actualContent)，我在做第二个：&#8220;当textbox失去焦点时自动格式化文本&#8221;的地方遇到了问题。。。</span></p>
<p><span style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">简单起见，简化成&#8220;当textbox失去焦点时改变文本内容&#8221;。</span></p>
<p><span style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">一种方法是：</span></p>
<p><span style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">重写OnLeave()方法，如下：</span><span style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"></span></p>
<div class=cnblogs_code><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">override</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;OnLeave(EventArgs&nbsp;e)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">base</span><span style="COLOR: #000000">.OnLeave(e);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.Text&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Override&nbsp;OnLeave</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">;<br>}</span></div>
<p>另一种是给Leave事件增加一个订阅者：</p>
<div class=cnblogs_code><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;NewReceiver(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000">&nbsp;sender,&nbsp;EventArgs&nbsp;e)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.text&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">NewReceiver</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Invalidate();<br>}<br><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">constructor</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;MyTextBox()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.Leave&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;EventHandler(NewReceiver);<br>}</span></div>
<p>经测试，均可运行。</p>
<p>现在，把两段代码和在一起，并注释掉第一种方法：</p>
<div class=cnblogs_code><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">override</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;OnLeave(EventArgs&nbsp;e)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">base</span><span style="COLOR: #000000">.OnLeave(e);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">this.Text&nbsp;=&nbsp;"Override&nbsp;OnLeave";</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">}<br><br></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;NewReceiver(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000">&nbsp;sender,&nbsp;EventArgs&nbsp;e)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.text&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">NewReceiver</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;Invalidate();<br>}<br><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">constuctor</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;MyTextBox()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.Leave&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;EventHandler(NewReceiver);<br>}</span></div>
<p>运行程序，测试，显示NewReceiver。</p>
<p>接下来再把base.OnLeave(e)注释掉：</p>
<div class=cnblogs_code><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">override</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;OnLeave(EventArgs&nbsp;e)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">base.OnLeave(e);<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">this.Text&nbsp;=&nbsp;"Override&nbsp;OnLeave";</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">}<br><br></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;NewReceiver(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000">&nbsp;sender,&nbsp;EventArgs&nbsp;e)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.text&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">NewReceiver</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;Invalidate();<br>}<br><br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">constuctor</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;MyTextBox()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.Leave&nbsp;</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;EventHandler(NewReceiver);<br>}</span></div>
<p>运行，发现文本框失去焦点后不会改变内容，仍未空。由此，第二种方法失效了。为何？我们来看一下base.OnLeave()的内容：</p>
<div class=cnblogs_code><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;OnLeave(EventArgs&nbsp;e)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;EventHandler&nbsp;handler&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;(EventHandler)&nbsp;</span><span style="COLOR: #0000ff">base</span><span style="COLOR: #000000">.Events[EventLeave];<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(handler&nbsp;</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handler(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">,&nbsp;e);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br></span></div>
<p>原来，注释掉这段以后，handler(this, e)无法得到执行，也就没法激发事件，文本框内容当然也就没法改变了。</p>
<p>&nbsp;</p>
<p>由此，我猜测，C#的事件触发过程大致是这样的：</p>
<p><span style="BACKGROUND-COLOR: gainsboro">文本框失去焦点 --&gt; 触发Leave事件 --&gt; 调用OnLeave()函数（<span style="COLOR: red">这里是因为什么机制调用的？</span>） --&gt; 调用base.OnLeave() --&gt; 再次触发Leave事件 --&gt; 调用NewReceiver() --&gt; 返回，执行this.text = "Override OnLeave"。</span></p>
<p>红色字，大家谁知道的，帮我解个惑吧～～</p>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59016.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-08-07 19:22 <a href="http://www.cppblog.com/pxhszcn/archive/2008/08/07/59016.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>just do it</title><link>http://www.cppblog.com/pxhszcn/archive/2008/08/02/59017.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Sat, 02 Aug 2008 09:35:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/08/02/59017.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59017.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/08/02/59017.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59017.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59017.html</trackback:ping><description><![CDATA[<p>很多东西，不是你不会做，而是你不敢去做。久而久之，庸庸碌碌。。</p>
<p>要这么想：有什么东西是天生就会的呢！</p>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59017.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-08-02 17:35 <a href="http://www.cppblog.com/pxhszcn/archive/2008/08/02/59017.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>同一个类的不同实例间private成员的相互访问</title><link>http://www.cppblog.com/pxhszcn/archive/2008/03/16/59019.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Sun, 16 Mar 2008 11:29:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/03/16/59019.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59019.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/03/16/59019.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59019.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59019.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;String<br><img id=Codehighlighter1_13_213_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_13_213_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_13_213_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_13_213_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_13_213_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_13_213_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_13_213_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_13_213_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_13_213_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_13_213_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;String(&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">str&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800000">""</span><span style="COLOR: #000000">&nbsp;);<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">String();<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;String(&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;String&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">another&nbsp;)<br><img id=Codehighlighter1_114_212_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_114_212_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_114_212_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_114_212_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_114_212_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_114_212_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_114_212_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_114_212_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_114_212_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_114_212_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">str&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;another.m_data;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;可以正常访问</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_177_183_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_177_183_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_177_183_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_177_183_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_177_183_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_177_183_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_177_183_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_177_183_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_177_183_Closed_Text>/**/</span><span id=Codehighlighter1_177_183_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">省略</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">m_data;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;</span></span></div>
<p>c＋＋里，类的访问权限是class level，不是object level的。<br>访问权限只在编译时对编译器有效，在运行时，不存在访问权限这道栅栏。&nbsp;&nbsp; <br></p>
<p>以下转自网上：<br><br>/** &nbsp; <br>&nbsp; &nbsp; * &nbsp; 请大家看看下面这段程序，它是能够正常编译连接运行的。但是为什么 &nbsp; <br>&nbsp; &nbsp; * &nbsp; assign成员函数没有错呢？谁能告诉我c++中关于这种情况的内幕？谢谢! &nbsp; <br>&nbsp; &nbsp; */ &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; #include &nbsp; &lt;stdio.h&gt; &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; class &nbsp; Test &nbsp; &nbsp; <br>&nbsp; { &nbsp; <br>&nbsp; private: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int &nbsp; a; &nbsp; <br>&nbsp; public: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Test(int); &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void &nbsp; assign(Test &nbsp; const* &nbsp; source); &nbsp; <br>&nbsp; }; &nbsp; &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; void &nbsp; Test::assign(Test &nbsp; *source) &nbsp; <br>&nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a &nbsp; = &nbsp; source-&gt;a; &nbsp; <br>&nbsp; } &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; int &nbsp; main() &nbsp; <br>&nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Test &nbsp; t1(1), &nbsp; t2(2); &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2.assign(&amp;t1); &nbsp; <br>&nbsp; } &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 1: &nbsp; 关于ACCESS-CONTROL的定义 &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &lt;&lt;C++98 &nbsp; std/chapter &nbsp; 11&gt;&gt;: &nbsp; <br>&nbsp; &nbsp; &nbsp; 1 &nbsp; A &nbsp; member &nbsp; of &nbsp; a &nbsp; class &nbsp; can &nbsp; be &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; --private; &nbsp; that &nbsp; is, &nbsp; its &nbsp; name &nbsp; can &nbsp; be &nbsp; used &nbsp; &nbsp; only &nbsp; &nbsp; by &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; member &nbsp; &nbsp; functions, &nbsp; static &nbsp; &nbsp; data &nbsp; &nbsp; members, &nbsp; &nbsp; and &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; friends &nbsp; &nbsp; of &nbsp; &nbsp; the &nbsp; &nbsp; class &nbsp; &nbsp; in &nbsp; which &nbsp; it &nbsp; is &nbsp; declared. &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; --protected; &nbsp; that &nbsp; is, &nbsp; its &nbsp; name &nbsp; can &nbsp; be &nbsp; used &nbsp; only &nbsp; by &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; member &nbsp; &nbsp; functions, &nbsp; static &nbsp; &nbsp; data &nbsp; &nbsp; members, &nbsp; &nbsp; and &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; friends &nbsp; &nbsp; of &nbsp; &nbsp; the &nbsp; &nbsp; class &nbsp; &nbsp; in &nbsp; which &nbsp; it &nbsp; is &nbsp; declared &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; by &nbsp; member &nbsp; functions, &nbsp; static &nbsp; data &nbsp; members, &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; &nbsp; friends &nbsp; of &nbsp; classes &nbsp; derived &nbsp; from &nbsp; this &nbsp; class. &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; --public; &nbsp; &nbsp; that &nbsp; &nbsp; is, &nbsp; &nbsp; its &nbsp; &nbsp; name &nbsp; &nbsp; can &nbsp; &nbsp; be &nbsp; &nbsp; used &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anywhere &nbsp; without &nbsp; access &nbsp; restriction. &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 2: &nbsp; 一些相关的note: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; 1) &nbsp; name &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; ACCESS-CONTROL &nbsp; 只应用到name（simple &nbsp; identifier). &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; 按照上面的定义，ACCESS-CONTROL针对且只针对 &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; member &nbsp; of &nbsp; class. &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; 即使是涉及到模板，也只是关心name, &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; 而不关心template-argument &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; 2) &nbsp; unnamed &nbsp; object &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; 无名对象不考虑access-control: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; 如下： &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; struct &nbsp; A &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; private: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; struct &nbsp; B &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int &nbsp; i; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B &nbsp; m_b; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; public: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B&amp; &nbsp; f() &nbsp; { &nbsp; return &nbsp; m_b; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; int &nbsp; main() &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A &nbsp; a; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f()-&gt;i; &nbsp; // &nbsp; only &nbsp; names &nbsp; are &nbsp; f, &nbsp; i, &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; f &nbsp; and &nbsp; i &nbsp; is &nbsp; public, &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; so &nbsp; it's &nbsp; legal &nbsp; even &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; if &nbsp; B &nbsp; in &nbsp; private &nbsp; A &nbsp; member &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; 3) &nbsp; 关于protected &nbsp; member &nbsp; name有一个例外情况， &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 参见(4:)中例子的new &nbsp; note &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 3: &nbsp; 让人迷惑的代码段的注记 &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; void &nbsp; Test::assign(Test &nbsp; *source) &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a &nbsp; = &nbsp; source-&gt;a; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /** &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1) &nbsp; 这里出现的name是 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void, &nbsp; Test, &nbsp; assign, &nbsp; source, &nbsp; a &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2) &nbsp; void, &nbsp; Test, &nbsp; source, &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 不是class &nbsp; member, &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 不做access-control考虑 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3) &nbsp; assign是成员函数名, &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 但我们只是定义它， &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 不在这里使用， &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 也不做access-control考虑 &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4）a是private &nbsp; Test &nbsp; member, &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 可以在A的成员函数中使用， &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 现在刚好是在Test的 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; assign成员函数体内。 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5) &nbsp; but &nbsp; what &nbsp; about &nbsp; "source-&gt;a": &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OK, &nbsp; a &nbsp; in &nbsp; "source-&gt;a" &nbsp; means &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a &nbsp; is &nbsp; a &nbsp; member &nbsp; name &nbsp; of &nbsp; source's &nbsp; class &nbsp; Test &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and &nbsp; used &nbsp; in &nbsp; Test &nbsp; member &nbsp; function, &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; everything &nbsp; is &nbsp; fine!!! &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (still &nbsp; confusing, &nbsp; see &nbsp; following &nbsp; example &nbsp; ...) &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */ &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; 4: &nbsp; 更加清楚的例子(我的）注记 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; struct &nbsp; Base &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; protected: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int &nbsp; m_protected; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; struct &nbsp; Son2 &nbsp; : &nbsp; Base &nbsp; {}; &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; struct &nbsp; Son1 &nbsp; : &nbsp; Base &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void &nbsp; foo(Son1&amp; &nbsp; s) &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s.m_protected;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /** &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new &nbsp; note: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; same &nbsp; as &nbsp; 3/5) &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */ &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void &nbsp; foo(Base&amp; &nbsp; b) &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.m_protected;&nbsp;&nbsp;&nbsp; /** &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new &nbsp; note: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_protected &nbsp; in &nbsp; "b.m_protected" &nbsp; means: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_protected &nbsp; is &nbsp; Base(b's &nbsp; type) &nbsp; class &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; member, &nbsp; not &nbsp; Son1 &nbsp; class &nbsp; member &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; which &nbsp; means: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Base's &nbsp; protected &nbsp; member &nbsp; is &nbsp; used &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; in &nbsp; Son1's &nbsp; member &nbsp; function &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; By &nbsp; definition, &nbsp; it's &nbsp; legal, &nbsp; but &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 因为C++标准规定一个关于 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; proected &nbsp; member的例外情况， &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; When &nbsp; a &nbsp; member &nbsp; function &nbsp; of &nbsp; a &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; derived &nbsp; &nbsp; class &nbsp; references &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a &nbsp; &nbsp; protected &nbsp; nonstatic &nbsp; member &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; of &nbsp; a &nbsp; base &nbsp; class, &nbsp; an &nbsp; access &nbsp; check &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; applies &nbsp; in &nbsp; addition &nbsp; &nbsp; to &nbsp; &nbsp; those &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; described &nbsp; earlier &nbsp; in &nbsp; this &nbsp; clause： &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Except &nbsp; when &nbsp; forming &nbsp; a &nbsp; pointer &nbsp; to &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; member,the &nbsp; access &nbsp; must &nbsp; be &nbsp; through &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a &nbsp; pointer &nbsp; to, &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reference &nbsp; to, &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;---我们的情况 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; or &nbsp; object &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;---下一个成员函数的情况 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; of &nbsp; the &nbsp; derived &nbsp; class &nbsp; itself &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (or &nbsp; any &nbsp; class &nbsp; derived &nbsp; from &nbsp; that &nbsp; class). &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 因为儿子不能管老子，所以结论是 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; illegal &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */ &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void &nbsp; foo(Base &nbsp; b) &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; b.m_protected;&nbsp; /** &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new &nbsp; note: &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; illegal &nbsp; : &nbsp; 儿子不能管老子 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 原因同 &nbsp; void &nbsp; foo(Base&amp; &nbsp; c)的分析。 &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */ &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; };&nbsp;&nbsp; <br><br></p>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59019.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-03-16 19:29 <a href="http://www.cppblog.com/pxhszcn/archive/2008/03/16/59019.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>字节对齐的问题</title><link>http://www.cppblog.com/pxhszcn/archive/2008/03/04/59021.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Tue, 04 Mar 2008 11:49:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/03/04/59021.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59021.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/03/04/59021.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59021.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59021.html</trackback:ping><description><![CDATA[<p><font face=Verdana>&nbsp;</p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><span style="COLOR: #000000">typedef&nbsp;unsigned&nbsp;</span><span style="COLOR: #0000ff">short</span><span style="COLOR: #000000">&nbsp;WORD;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif">typedef&nbsp;unsigned&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;DWORD;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif">typedef&nbsp;unsigned&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;BYTE;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif">typedef&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;LONG;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;BITMAPFILEHEADER<br><img id=Codehighlighter1_132_220_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_132_220_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_132_220_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_132_220_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_132_220_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_132_220_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_132_220_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_132_220_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_132_220_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_132_220_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;WORD&nbsp;bfType;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;DWORD&nbsp;bfSize;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;WORD&nbsp;bfReserved1;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;WORD&nbsp;bfReserved2;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;DWORD&nbsp;bfOffBits;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000">;<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"></span></div>
<p>sizeof(WORD)==2<br>sizeof(DWORD)==4<br>但sizeof(BITMAPFILEHEADER)==16&nbsp;<br>不等于2+4+2+2+4=14<br>为什么？这里存在一个字节对齐问题<br>以下为转帖：<br></p>
<h3>一.什么是字节对齐,为什么要对齐?</h3>
<p>&nbsp;&nbsp;&nbsp; 现代计算机中内存空间都是按照byte划分的，从理论上讲似乎对任何类型的变量的访问可以从任何地址开始，但实际情况是在访问特定类型变量的时候经常在特 定的内存地址访问，这就需要各种类型数据按照一定的规则在空间上排列，而不是顺序的一个接一个的排放，这就是对齐。<br>&nbsp;&nbsp;&nbsp; 对齐的作用和原因：各个硬件平台对存储空间的处理上有很大的不同。一些平台对某些特定类型的数据只能从某些特定地址开始存取。比如有些架构的CPU在访问 一个没有进行对齐的变量的时候会发生错误,那么在这种架构下编程必须保证字节对齐.其他平台可能没有这种情况，但是最常见的是如果不按照适合其平台要求对 数据存放进行对齐，会在存取效率上带来损失。比如有些平台每次读都是从偶地址开始，如果一个int型（假设为32位系统）如果存放在偶地址开始的地方，那 么一个读周期就可以读出这32bit，而如果存放在奇地址开始的地方，就需要2个读周期，并对两次读出的结果的高低字节进行拼凑才能得到该32bit数 据。显然在读取效率上下降很多。</p>
<h3>二.字节对齐对程序的影响:</h3>
<p>&nbsp;&nbsp;&nbsp; 先让我们看几个例子吧(32bit,x86环境,gcc编译器):<br>设结构体如下定义：<br>struct A<br>{<br>&nbsp;&nbsp;&nbsp; int a;<br>&nbsp;&nbsp;&nbsp; char b;<br>&nbsp;&nbsp;&nbsp; short c;<br>};<br>struct B<br>{<br>&nbsp;&nbsp;&nbsp; char b;<br>&nbsp;&nbsp;&nbsp; int a;<br>&nbsp;&nbsp;&nbsp; short c;<br>};<br>现在已知32位机器上各种数据类型的长度如下:<br>char:1(有符号无符号同)&nbsp;&nbsp;&nbsp;&nbsp;<br>short:2(有符号无符号同)&nbsp;&nbsp;&nbsp;&nbsp;<br>int:4(有符号无符号同)&nbsp;&nbsp;&nbsp;&nbsp;<br>long:4(有符号无符号同)&nbsp;&nbsp;&nbsp;&nbsp;<br>float:4&nbsp;&nbsp;&nbsp;&nbsp;double:8<br>那么上面两个结构大小如何呢?<br>结果是:<br>sizeof(strcut A)值为8<br>sizeof(struct B)的值却是12</p>
<p>结构体A中包含了4字节长度的int一个，1字节长度的char一个和2字节长度的short型数据一个,B也一样;按理说A,B大小应该都是7字节。<br>之所以出现上面的结果是因为编译器要对数据成员在空间上进行对齐。上面是按照编译器的默认设置进行对齐的结果,那么我们是不是可以改变编译器的这种默认对齐设置呢,当然可以.例如:<br>#pragma pack (2) /*指定按2字节对齐*/<br>struct C<br>{<br>&nbsp;&nbsp;&nbsp; char b;<br>&nbsp;&nbsp;&nbsp; int a;<br>&nbsp;&nbsp;&nbsp; short c;<br>};<br>#pragma pack () /*取消指定对齐，恢复缺省对齐*/<br>sizeof(struct C)值是8。<br>修改对齐值为1：<br>#pragma pack (1) /*指定按1字节对齐*/<br>struct D<br>{<br>&nbsp;&nbsp;&nbsp; char b;<br>&nbsp;&nbsp;&nbsp; int a;<br>&nbsp;&nbsp;&nbsp; short c;<br>};<br>#pragma pack () /*取消指定对齐，恢复缺省对齐*/<br>sizeof(struct D)值为7。<br>后面我们再讲解#pragma pack()的作用.</p>
<h3>三.编译器是按照什么样的原则进行对齐的?</h3>
<p>&nbsp;&nbsp;&nbsp; 先让我们看四个重要的基本概念：<br><font color=#0000ff>1.数据类型自身的对齐值：<br></font>&nbsp; 对于char型数据，其自身对齐值为1，对于short型为2，对于int,float,double类型，其自身对齐值为4，单位字节。<br><font color=#3300ff>2.结构体或者类的自身对齐值：</font>其成员中自身对齐值最大的那个值。<br><font color=#0000ff>3.指定对齐值</font>：#pragma pack (value)时的指定对齐值value。<br><font color=#0000ff>4.数据成员、结构体和类的有效对齐值：</font>自身对齐值和指定对齐值中小的那个值。<br>有 了这些值，我们就可以很方便的来讨论具体数据结构的成员和其自身的对齐方式。有效对齐值N是最终用来决定数据存放地址方式的值，最重要。有效对齐N，就是 表示&#8220;对齐在N上&#8221;，也就是说该数据的"存放起始地址%N=0".而数据结构中的数据变量都是按定义的先后顺序来排放的。第一个数据变量的起始地址就是数 据结构的起始地址。结构体的成员变量要对齐排放，结构体本身也要根据自身的有效对齐值圆整(就是结构体成员变量占用总长度需要是对结构体有效对齐值的整数 倍，结合下面例子理解)。这样就不能理解上面的几个例子的值了。<br>例子分析：<br>分析例子B；<br>struct B<br>{<br>&nbsp;&nbsp;&nbsp; char b;<br>&nbsp;&nbsp;&nbsp; int a;<br>&nbsp;&nbsp;&nbsp; short c;<br>};<br>假 设B从地址空间0x0000开始排放。该例子中没有定义指定对齐值，在笔者环境下，该值默认为4。第一个成员变量b的自身对齐值是1，比指定或者默认指定 对齐值4小，所以其有效对齐值为1，所以其存放地址0x0000符合0x0000%1=0.第二个成员变量a，其自身对齐值为4，所以有效对齐值也为4， 所以只能存放在起始地址为0x0004到0x0007这四个连续的字节空间中，复核0x0004%4=0,且紧靠第一个变量。第三个变量c,自身对齐值为 2，所以有效对齐值也是2，可以存放在0x0008到0x0009这两个字节空间中，符合0x0008%2=0。所以从0x0000到0x0009存放的 都是B内容。再看数据结构B的自身对齐值为其变量中最大对齐值(这里是b）所以就是4，所以结构体的有效对齐值也是4。根据结构体圆整的要求， 0x0009到0x0000=10字节，（10＋2）％4＝0。所以0x0000A到0x000B也为结构体B所占用。故B从0x0000到0x000B 共有12个字节,sizeof(struct B)=12;<font color=#3300ff>其实如果就这一个就来说它已将满足字节对齐了, 因为它的起始地址是0,因此肯定是对齐的,之所以在后面补充2个字节,是因为编译器为了实现结构数组的存取效率,试想如果我们定义了一个结构B的数组,那 么第一个结构起始地址是0没有问题,但是第二个结构呢?按照数组的定义,数组中所有元素都是紧挨着的,如果我们不把结构的大小补充为4的整数倍,那么下一 个结构的起始地址将是0x0000A,这显然不能满足结构的地址对齐了,因此我们要把结构补充成有效对齐大小的整数倍.其实诸如:对于char型数据，其 自身对齐值为1，对于short型为2，对于int,float,double类型，其自身对齐值为4，这些已有类型的自身对齐值也是基于数组考虑的,只 是因为这些类型的长度已知了,所以他们的自身对齐值也就已知了.<br></font>同理,分析上面例子C：<br>#pragma pack (2) /*指定按2字节对齐*/<br>struct C<br>{<br>&nbsp;&nbsp;&nbsp; char b;<br>&nbsp;&nbsp;&nbsp; int a;<br>&nbsp;&nbsp;&nbsp; short c;<br>};<br>#pragma pack () /*取消指定对齐，恢复缺省对齐*/<br>第 一个变量b的自身对齐值为1，指定对齐值为2，所以，其有效对齐值为1，假设C从0x0000开始，那么b存放在0x0000，符合0x0000%1= 0;第二个变量，自身对齐值为4，指定对齐值为2，所以有效对齐值为2，所以顺序存放在0x0002、0x0003、0x0004、0x0005四个连续 字节中，符合0x0002%2=0。第三个变量c的自身对齐值为2，所以有效对齐值为2，顺序存放<br>在0x0006、0x0007中，符合 0x0006%2=0。所以从0x0000到0x00007共八字节存放的是C的变量。又C的自身对齐值为4，所以C的有效对齐值为2。又8%2=0,C 只占用0x0000到0x0007的八个字节。所以sizeof(struct C)=8.</p>
<h3>四.如何修改编译器的默认对齐值?</h3>
<p>1.在VC IDE中，可以这样修改：[Project]|[Settings],c/c++选项卡Category的Code Generation选项的Struct Member Alignment中修改，默认是8字节。<br>2.在编码时，可以这样动态修改：#pragma pack .<font color=#ff0000>注意:是pragma而不是progma.</font></p>
<h3>五.针对字节对齐,我们在编程中如何考虑?</h3>
<p><br>&nbsp;&nbsp;&nbsp; 如果在编程的时候要考虑节约空间的话,那么我们只需要假定结构的首地址是0,然后各个变量按照上面的原则进行排列即可,基本的原则就是把结构中的变量按照 类型大小从小到大声明,尽量减少中间的填补空间.还有一种就是为了以空间换取时间的效率,我们显示的进行填补空间进行对齐,比如:有一种使用空间换时间做 法是显式的插入reserved成员：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct A{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char a;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char reserved[3];//使用空间换时间<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int b;<br>}<br><br>reserved成员对我们的程序没有什么意义,它只是起到填补空间以达到字节对齐的目的,当然即使不加这个成员通常编译器也会给我们自动填补对齐,我们自己加上它只是起到显式的提醒作用.</p>
<h3>六.字节对齐可能带来的隐患:</h3>
<p>&nbsp;&nbsp;&nbsp; 代码中关于对齐的隐患，很多是隐式的。比如在强制类型转换的时候。例如：<br>unsigned int i = 0x12345678;<br>unsigned char *p=NULL;<br>unsigned short *p1=NULL;</p>
<p>p=&amp;i;<br>*p=0x00;<br>p1=(unsigned short *)(p+1);<br>*p1=0x0000;<br>最后两句代码，从奇数边界去访问unsignedshort型变量，显然不符合对齐的规定。<br>在x86上，类似的操作只会影响效率，但是在MIPS或者sparc上，可能就是一个error,因为它们要求必须字节对齐.</p>
<h3>七.如何查找与字节对齐方面的问题:</h3>
<p>如果出现对齐或者赋值问题首先查看<br>1. 编译器的big little端设置<br>2. 看这种体系本身是否支持非对齐访问<br>3. 如果支持看设置了对齐与否,如果没有则看访问时需要加某些特殊的修饰来标志其特殊访问操作。</p>
<strong>
<p><span style="FONT-SIZE: 14pt">八.其他</span></p>
<p>当数据定义中出现__declspec(&nbsp;align()&nbsp;)时，指定类型的对齐长度还要用自身长度和这里指定的数值比较，然后取其中较大的。最终类/结构的对齐长度也需要和这个数值比较，然后取其中较大的。</strong><br><br>可以这样理解，<!--startfragment --> __declspec(&nbsp;align()&nbsp;) 和 #pragma pack是一对兄弟，前者规定了对齐的最小值，后者规定了对齐的最大值，两者同时出现时，前者拥有更高的优先级。<br>__declspec(&nbsp;align()&nbsp;)的一个特点是，它仅仅规定了数据对齐的位置，而没有规定数据实际占用的内存长度，当指定的数据被放置在确定的位置之后，其后的数据填充仍然是按照#pragma pack规定的方式填充的，这时候类/结构的实际大小和内存格局的规则是这样的：<br>在__declspec(&nbsp;align()&nbsp;)之前，数据按照#pragma pack规定的方式填充，如前所述。当遇到__declspec(&nbsp;align()&nbsp;)的时候，首先寻找距离当前偏移向后最近的对齐点（满足对齐长度为max(数据自身长度,指定值) )，然后把被指定的数据类型从这个点开始填充，其后的数据类型从它的后面开始，仍然按照#pragma pack填充，直到遇到下一个__declspec(&nbsp;align()&nbsp;)。<br>当所有数据填充完毕，把结构的整体对齐数值和__declspec(&nbsp;align()&nbsp;)规定的值做比较，取其中较大的作为整个结构的对齐长度。<br>特别的，当__declspec(&nbsp;align()&nbsp;)指定的数值比对应类型长度小的时候，这个指定不起作用。<br></p>
</font><font face=Verdana></font>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59021.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-03-04 19:49 <a href="http://www.cppblog.com/pxhszcn/archive/2008/03/04/59021.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>类模板的分离编译</title><link>http://www.cppblog.com/pxhszcn/archive/2008/01/31/59024.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Thu, 31 Jan 2008 08:26:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/01/31/59024.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59024.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/01/31/59024.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59024.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59024.html</trackback:ping><description><![CDATA[<p><font face=Verdana></font></p>
<font face=Verdana>
<p><br>&nbsp;</p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img id=Codehighlighter1_0_61_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_0_61_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_0_61_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_0_61_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_0_61_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_0_61_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_0_61_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_0_61_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_0_61_Closed_Text>/**/</span><span id=Codehighlighter1_0_61_Open_Text><span style="COLOR: #808080">////////////////////////////////////////////////////////////</span></span><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;filename:&nbsp;seqlist.h&nbsp;类模板的申明</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_91_152_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_91_152_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_91_152_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_91_152_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_91_152_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_91_152_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_91_152_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_91_152_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_91_152_Closed_Text>/**/</span><span id=Codehighlighter1_91_152_Open_Text><span style="COLOR: #808080">////////////////////////////////////////////////////////////</span></span><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#ifndef&nbsp;SEQLIST<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;SEQLIST</span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif">template</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">calss&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;SeqList<br><img id=Codehighlighter1_217_225_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_217_225_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_217_225_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_217_225_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_217_225_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_217_225_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_217_225_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_217_225_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_217_225_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_217_225_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;<img alt="" src="http://www.cnblogs.com/Images/dot.gif"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_227_288_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_227_288_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_227_288_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_227_288_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_227_288_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_227_288_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_227_288_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_227_288_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_227_288_Closed_Text>/**/</span><span id=Codehighlighter1_227_288_Open_Text><span style="COLOR: #808080">////////////////////////////////////////////////////////////</span></span><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;filename:&nbsp;seqlist.cpp&nbsp;类模板的定义</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_320_381_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_320_381_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_320_381_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_320_381_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_320_381_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_320_381_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_320_381_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_320_381_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_320_381_Closed_Text>/**/</span><span id=Codehighlighter1_320_381_Open_Text><span style="COLOR: #808080">////////////////////////////////////////////////////////////</span></span><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#include</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">seqlist.h</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif">template</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif">SeqList</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::SeqList(<img alt="" src="http://www.cnblogs.com/Images/dot.gif">)<br><img id=Codehighlighter1_445_453_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_445_453_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_445_453_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_445_453_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_445_453_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_445_453_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_445_453_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_445_453_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_445_453_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_445_453_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;<img alt="" src="http://www.cnblogs.com/Images/dot.gif"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><br><img id=Codehighlighter1_455_516_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_455_516_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_455_516_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_455_516_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_455_516_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_455_516_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_455_516_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_455_516_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_455_516_Closed_Text>/**/</span><span id=Codehighlighter1_455_516_Open_Text><span style="COLOR: #808080">////////////////////////////////////////////////////////////</span></span><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;filename:&nbsp;main.cpp&nbsp;主函数</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_542_603_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_542_603_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_542_603_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_542_603_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_542_603_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_542_603_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_542_603_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_542_603_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_542_603_Closed_Text>/**/</span><span id=Codehighlighter1_542_603_Open_Text><span style="COLOR: #808080">////////////////////////////////////////////////////////////</span></span><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#include</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">seqlist.h</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif">#include</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br><img id=Codehighlighter1_653_661_Open_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_653_661_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_653_661_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_653_661_Closed_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_653_661_Closed_Image onclick="this.style.display='none'; document.getElementById('Codehighlighter1_653_661_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_653_661_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_653_661_Open_Text').style.display='inline';" alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_653_661_Closed_Text><img alt="" src="http://www.cnblogs.com/Images/dot.gif"></span><span id=Codehighlighter1_653_661_Open_Text><span style="COLOR: #000000">{<br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/InBlock.gif">&nbsp;<img alt="" src="http://www.cnblogs.com/Images/dot.gif"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img alt="" align=top src="http://www.cnblogs.com/images/OutliningIndicators/None.gif"></span></div>
<p>&nbsp;</p>
<p>如以上写法，连接时会出错，这个问题属于类模板的分离编译，有三种解决办法：<br>1. 将类模板申明与类模板定义放到一个文件中。<br>2. 在主函数中加 #include"seqlist.cpp"。<br>3. 使用export关键字。</p>
<p>c++primer中讲到"c++的模板编译模式"有两种——"包含编译和分离编译"。详见c++primer 16.8</font></p>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59024.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-01-31 16:26 <a href="http://www.cppblog.com/pxhszcn/archive/2008/01/31/59024.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一些概念。。(typedef, __stdcall __cdecl)</title><link>http://www.cppblog.com/pxhszcn/archive/2008/01/23/59026.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Wed, 23 Jan 2008 02:03:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/01/23/59026.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59026.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/01/23/59026.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59026.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59026.html</trackback:ping><description><![CDATA[<p><br>&nbsp;<strong>typedef:<br></strong></p>
<font face=Verdana>
<p>第一个陷阱：<br>typedef char * pstr;<br>int mystrcmp(pstr, pstr);　　<br></font><font face=Verdana>int mystrcmp(const pstr, const pstr); 　　<br></font><font face=Verdana>这是错误的，按照顺序，&#8216;const pstr&#8217;被解释为&#8216;char * const&#8217;（一个指向 char 的常量指针），而不是&#8216;const char *&#8217;（指向常量 char 的指针）。这个问题很容易解决：</font></p>
<p><font face=Verdana>typedef const char * cpstr;<br></font><font face=Verdana>int mystrcmp(cpstr, cpstr); // 现在是正确的</font></p>
<p>第二个陷阱：<br><font face=Verdana>typedef register int FAST_COUNTER; // 错误　　<br></font><font face=Verdana>编译通不过。问题出在你不能在声明中有多个存储类关键字。因为符号 typedef 已经占据了存储类关键字的位置，在 typedef 声明中不能用 register（或任何其它存储类关键字）。<br></font>&nbsp;<br>和#define区别：<br>#define：编译与处理时<br>typedef：编译时</p>
<table style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" class=MsoNormalTable border=1 cellSpacing=0 cellPadding=0>
    <tbody>
        <tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes">
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=center><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=center><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>__cdecl</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=center><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;</span> <strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></strong></p>
            </td>
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #ece9d8; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=center><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: center; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=center><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>__stdcall</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 10pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></strong></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 1">
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">和</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C++</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">程序的缺省调用规范</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #ece9d8; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">为了使用这种调用规范，需要你明确的加上</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>__stdcall</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">（或</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>WINAPI</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">）文字。即</span> <em><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>return-type</span> </em><em></em><strong><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>__stdcall</span> </strong><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><em>function-name</em>[(<em>argument-list</em>)]</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 2">
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">在<strong style="mso-bidi-font-weight: normal">被</strong>调用函数</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>(Callee)</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">返回<strong style="mso-bidi-font-weight: normal">后</strong>，由调用方</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>(Caller)</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">调整堆栈。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p>&nbsp;</o:p> </span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>1. </span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">调用方的函数调用<span lang=EN-US><o:p></o:p></span></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 9">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>2. </span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">被调用函数的执行<span lang=EN-US><o:p></o:p></span></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p> </span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>3. </span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">被调用函数的结果返回<span lang=EN-US><o:p></o:p></span></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p> </span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; COLOR: red; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>4. </span><span style="FONT-FAMILY: 宋体; COLOR: red; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">调用方清除调整堆栈</span> <span style="FONT-FAMILY: 宋体; COLOR: red; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #ece9d8; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">在<strong style="mso-bidi-font-weight: normal">被</strong>调用函数</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>(Callee)</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">返回<strong style="mso-bidi-font-weight: normal">前</strong>，由<strong style="mso-bidi-font-weight: normal">被</strong>调用函数</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>(Callee)</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">调整堆栈。图示：</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p>&nbsp;</o:p> </span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>1. </span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">调用方的函数调用<span lang=EN-US><o:p></o:p></span></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p> </span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>2. </span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">被调用函数的执行<span lang=EN-US><o:p></o:p></span></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p> </span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; COLOR: red; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>3. </span><span style="FONT-FAMILY: 宋体; COLOR: red; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">被调用函数清除调整堆栈<span lang=EN-US><o:p></o:p></span></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p>&nbsp;</o:p> </span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>4. </span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">被调用函数的结果返回</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><span style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count: 5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 3">
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">因为每个调用的地方都需要生成一段调整堆栈的代码，所以最后生成的文件较大。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang=EN-US><o:p></o:p></span></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #ece9d8; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">因为调整堆栈的代码只存在在一个地方（被调用函数的代码内），所以最后生成的文件较小。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 4">
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">函数的参数个数可变（就像</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>printf</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">函数一样），因为只有调用者才知道它传给被调用函数几个参数，才能在调用结束时适当地调整堆栈。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang=EN-US><o:p></o:p></span></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #ece9d8; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">函数的参数个数不能是可变的。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 5">
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">对于定义在</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">程序文件中的输出函数，函数名会保持原样，不会被修饰。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">对于定义在</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C++</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">程序文件中的输出函数，函数名会被修饰， </span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>MSDN</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">说</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>Underscore character (_) is prefixed to names</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>. </span><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">我实际测试（</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>VC4</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">和</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>VC6</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">）下来发现好像不是那么简单。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">可通过在前面加上</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>extern </span></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt">&#8220;<span lang=EN>C</span>&#8221;</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">以去除函数名修饰。也可通过</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>.def</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">文件去除函数名修饰。</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></strong></p>
            </td>
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #ece9d8; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">不论是</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">程序文件中的输出函数还是</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C++</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">程序文件中的输出函数，函数名都会被修饰。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">对于定义在</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">程序文件中的输出函数，</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list.</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">对于定义在</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C++</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">程序文件中的输出函数，好像更复杂，和</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>__cdecl</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">的情况类似。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">好像只能通过</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>.def</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><strong style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">文件去除函数名修饰。</span> </strong><strong style="mso-bidi-font-weight: normal"></strong><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 6">
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>_beginthread</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">需要</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>__cdecl</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt">的线程函数地址</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang=EN-US><o:p></o:p></span></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            </td>
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: #ece9d8; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 217.55pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=290>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>_beginthreadex</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">和</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>CreateThread</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">需要</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>__stdcall</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt">的线程函数地址</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang=EN-US><o:p></o:p></span></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            </td>
        </tr>
        <tr style="mso-yfti-irow: 7; mso-yfti-lastrow: yes">
            <td style="BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; PADDING-BOTTOM: 0cm; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 435.1pt; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: windowtext 1pt solid; PADDING-TOP: 0cm; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" vAlign=top width=580 colSpan=2>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>&nbsp;<o:p></o:p></span> </p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">两者的参数传递顺序都是从右向左。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN><o:p></o:p></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">为了让</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>VB</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">可以调用，需要用</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-fareast-font-family: 'MS Mincho'; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>__stdcall</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">调用规范来定义</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>C/C++</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">函数。请参看<span lang=EN-US>Microsoft KB153586 </span>文章：<span lang=EN-US><a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;Q153586"><span style="COLOR: blue; mso-bidi-font-size: 11.0pt">How To Call C Functions That Use the _cdecl Calling Convention</span></a></span>。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang=EN-US><o:p></o:p></span></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">当你</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>LoadLibrary</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">一个</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>DLL</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">文件后， 把</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>GetProcAddress</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">取得的函数地址传给上面三个线程生成函数时，请务必确认实际定义在</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>DLL</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">文件的输出函数符合调用规范要求。否则，编译成</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-ansi-language: EN; mso-font-kerning: 0pt" lang=EN>Release</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">版后运行，可能会破坏堆栈，程序行为不可预测。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang=EN-US><o:p></o:p></span></span></p>
            <p style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left><span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt" lang=EN-US>VC</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 9pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">中的相关编译开关：<span lang=EN-US>/Gd /Gr /Gz</span>。另外，<span lang=EN-US>VC6</span>中新增加的<span lang=EN-US> /GZ </span>编译开关可以帮你检查堆栈问题。</span> <span style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span lang=EN-US><o:p></o:p></span></span></p>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59026.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-01-23 10:03 <a href="http://www.cppblog.com/pxhszcn/archive/2008/01/23/59026.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>换硬盘啦</title><link>http://www.cppblog.com/pxhszcn/archive/2008/01/20/59030.html</link><dc:creator>彭小虎(Tigerkin)</dc:creator><author>彭小虎(Tigerkin)</author><pubDate>Sun, 20 Jan 2008 13:24:00 GMT</pubDate><guid>http://www.cppblog.com/pxhszcn/archive/2008/01/20/59030.html</guid><wfw:comment>http://www.cppblog.com/pxhszcn/comments/59030.html</wfw:comment><comments>http://www.cppblog.com/pxhszcn/archive/2008/01/20/59030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/pxhszcn/comments/commentRss/59030.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/pxhszcn/services/trackbacks/59030.html</trackback:ping><description><![CDATA[<p>120G日立笔记本硬盘今天到手~~<br>我那30G的前辈也正式退役干起了移动硬盘~哈<br>换了硬盘不仅增大了我的空间，更出乎意料地加快了电脑的速度，5400RPM+垂直技术 &gt; 4200RPM ，实践证明，硬盘真是个大瓶颈！~</p>
<img src ="http://www.cppblog.com/pxhszcn/aggbug/59030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/pxhszcn/" target="_blank">彭小虎(Tigerkin)</a> 2008-01-20 21:24 <a href="http://www.cppblog.com/pxhszcn/archive/2008/01/20/59030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>