<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>从此开始。。。</title>
	<atom:link href="http://blog.donews.com/skyfei/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.donews.com/skyfei</link>
	<description>努力工作，开心生活</description>
	<lastBuildDate>Fri, 28 Jan 2005 02:16:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>你的女朋友值多少钱？</title>
		<link>http://blog.donews.com/skyfei/archive/2005/01/28/259865.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2005/01/28/259865.aspx#comments</comments>
		<pubDate>Fri, 28 Jan 2005 02:16:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2005/01/28/259865.aspx</guid>
		<description><![CDATA[ 摘自：

 天外飞猪 发贴时间：2005-1-12 9:55:00  绿土地论坛]]></description>
			<content:encoded><![CDATA[<p class="ppp">女主持人气势咄咄的问一个男嘉宾，你为什么那么在乎钱，男嘉宾说：“钱能买到一切!”<br/>    现场的观众哗然了。<br/>    男嘉宾微笑的说：“我们做个测试吧。”<br/>    一个很简单的主题，你的一个仇人爱上了你的女友，现在想要你退出，你是一个正常的人，你爱自己的女友。那个男人愿意出一点钱来补偿你。<br/>    所有的观众都很不屑这种论调，男人缓缓的开出了第一个价格“五万!”<br/>    现场的观众松了口气，论点很集中：“五万，简直是瞧不起人，为了五万放弃了爱情？更主要的是放弃了自己的人格”所有的人都不约而同的否定了。<br/>    男人接着开出了第二个价格“五十万!”<br/>    现场的声音小了很多，一部分的人开始自己的计算了，在过了好大的一会儿，绝大多数的男人依然选择了否定，他身边的女友感动的看着他。只有少数的人接受了这五十万，其中的一个人说：“自己没有钱，父母苦了一辈子了，临老了生病没钱医治，为了父母，放弃了爱情吧。”<br/>    男人接着开出了第三个价格“五百万!”<br/>    现场更静了，男人的第一个动作都是看身边的女人，也许是在权衡什么。一半的男人沉默了，另一半的男人怯生生的说:“我要爱情。”身边的女友也有点呆住了，一个女孩子站起来说：“如果一个男人肯出五百万，我想我没有理由拒绝他。”沉默的男人选择了金钱，五百万可以买一套房子，一部车子，全家过上好日子，甚至可以开始自己的事业。一个男人说：“他是我的仇人，我有了这个五百万，我可以含辛茹苦，我可以报仇，我可以计划我所有的未来，当个真正主宰自己的男人。”一些女人看着身边的男人，若有所思。<br/>    男人接着开出了第四个价格“五千万”<br/>    全场哗然了，对于大多数的人，一辈子也挣不了这许多。女人说:“有肯为我一掷五千万的男人，他一定是爱我的，这样有钱又专一的男人，为什么不选择呢。”一个男人举手:“他真的肯付五千万？”在得到肯定的回答后，男人说:“爱情是无价的，但是我没有这个能力去照顾爱人，别人有，我应该放弃，并且我有了这许多的钱，我可以做很多有意义的事情，我可以成就事业，我可以帮助别人，这样的人生才有意义。”所有的人都深以为然。<br/>    只有一个人依然选择了放弃，所有的人都用很奇怪的目光看他，他解释到：“我的爱情是无价的”，当问到他的女友是否感动的时候，女友说：“我虽然感动，但我更感动的是为了我付出自己五千万的人，而不是放弃别人的五千万，他的观点很可敬，但不现实。”<br/>    嘉宾笑了笑，你们所有的人都选择了金钱。<br/>    那个人还是以前的那个人，他的为人和评价只是因为钱的变化而完全改变了；爱情是无价的，也只是面对钱多钱少的时候。<br/>    钱多就高尚了。所有无价的都是都是跟钱比较的，博物馆里的国宝，有钱了可以买，买不到了可以雇人偷和抢，再不行的话，可以发动战争，只要你有足够的钱。<br/>    美国打伊拉克需要的是什么，钱；使用的是什么，还是钱，不过是一个以钱换钱的游戏罢了。<br/>    所有的观众愕然了，想起自己的生活。<br/>    想跳槽的时候，借口都不是钱，但都有一个理由:“我不在乎钱，但是我在乎工资，这代表我是否受尊重和我的价值。”是啊，相同的工作，一千块就侮辱了你，一万块就是尊重你，十次的侮辱等于尊重？<br/>    嘉宾说，我不想解释为量变导致质变，爱情的质变不是钱多钱少的问题，而是，在你们之间叫的爱情如果通过交换就不叫了爱情。所以他拿钱换走的不是爱情，而是你的所有权，爱情已经走了，它依然无价！变质的爱情怎么还能叫爱情？<br/>    所有的人性都有价格，而又无价，当你用金钱换取的时候，人性已经丢掉了，你售卖的价格已经和你原有的人性无关。<br/>    嘉宾最后说了一句，我相信爱情，相信所有的人性，所以我努力的挣钱、爱钱。我只是不希望我的爱情和人性受到别人的金钱的考验罢了<br/>    钱重要吗？？</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2005/01/28/259865.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WMI应用</title>
		<link>http://blog.donews.com/skyfei/archive/2005/01/26/257685.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2005/01/26/257685.aspx#comments</comments>
		<pubDate>Wed, 26 Jan 2005 04:16:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2005/01/26/257685.aspx</guid>
		<description><![CDATA[private void button1_Click(object sender, System.EventArgs e)         {             string strsearch=string.Format(@&#8221;SELECT MACAddress FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL)AND (Manufacturer &#60;&#62; &#8217;Microsoft&#8217;))&#8220;);              System.Management.ManagementObjectSearcher msearch=new ManagementObjectSearcher();              msearch.Scope=new ManagementScope(@&#8221;root\CIMV2&#8220;);             msearch.Query=new ObjectQuery(strsearch);             int i=1;             try             {                 if((msearch.Get().Count&#60;1) &#124;&#124; (msearch.Get()==null))                 {                     this.listBox1.Items.Add(&#8220;No MAC Address!&#8220;);                 }                 else                 {                     foreach(System.Management.ManagementObject mymac in msearch.Get())                     {                         string str1=string.Format(&#8220;MAC{0} address:{1}&#8220;,i.ToString(),mymac["MACAddress"].ToString());                         this.listBox1.Items.Add(str1);                         i++;                     }                 }             }             catch(Exception ex)             {                 string msg=ex.Message.ToString();                 MessageBox.Show(&#8220;erro&#8220;, msg);             }          } 

WMI的应用 



来源： maqiaos_cn 阅读：1476 次 日期：2004-7-30 






作  者：maqiaos_cn 发表于：2003-1-16
    WMI(Windows Management Instrumentation)技术是微软提供的Windows下的系统管理工具。 通过该工具可以在本地或者管理客户端系统中几乎一切的信息。很多专业的网络管理工具都是 基于WMI开发的。该工具在Win2000以及WinNT下是标准工具，在Win9X下是扩展安装选项。本文 将介绍如何通过VB编程来访问WMI对象的编程。    首先来看一个简单的通过WMI获取系统信息的范例，这个范例通过WMI对象获得系统中运行 的的进程： Function Enum1() As String     Dim [...]]]></description>
			<content:encoded><![CDATA[<p><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> button1_Click(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, System.EventArgs e) <br/><img id="Codehighlighter1_64_911_Open_Image" onclick="this.style.display='none'; Codehighlighter1_64_911_Open_Text.style.display='none'; Codehighlighter1_64_911_Closed_Image.style.display='inline'; Codehighlighter1_64_911_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" alt=""/><img id="Codehighlighter1_64_911_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_64_911_Closed_Text.style.display='none'; Codehighlighter1_64_911_Open_Image.style.display='inline'; Codehighlighter1_64_911_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" alt=""/>        </span><span id="Codehighlighter1_64_911_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" alt=""/></span><span id="Codehighlighter1_64_911_Open_Text"><span style="COLOR: #000000">{ <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> strsearch</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.Format(</span><span style="COLOR: #000000">@&#8221;</span><span style="COLOR: #000000">SELECT MACAddress FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL)AND (Manufacturer &lt;&gt; &#8217;Microsoft&#8217;))</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">); <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/> <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>            System.Management.ManagementObjectSearcher msearch</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ManagementObjectSearcher();  <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>            msearch.Scope</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ManagementScope(</span><span style="COLOR: #000000">@&#8221;</span><span style="COLOR: #000000">root\CIMV2</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">); <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>            msearch.Query</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ObjectQuery(strsearch); <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>            </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>            </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> <br/><img id="Codehighlighter1_424_801_Open_Image" onclick="this.style.display='none'; Codehighlighter1_424_801_Open_Text.style.display='none'; Codehighlighter1_424_801_Closed_Image.style.display='inline'; Codehighlighter1_424_801_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" width="11" align="top" alt=""/><img id="Codehighlighter1_424_801_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_424_801_Closed_Text.style.display='none'; Codehighlighter1_424_801_Open_Image.style.display='inline'; Codehighlighter1_424_801_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" width="11" align="top" alt=""/>            </span><span id="Codehighlighter1_424_801_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" alt=""/></span><span id="Codehighlighter1_424_801_Open_Text"><span style="COLOR: #000000">{ <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">((msearch.Get().Count</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">) </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> (msearch.Get()</span><span style="COLOR: #000000">==</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">)) <br/><img id="Codehighlighter1_487_542_Open_Image" onclick="this.style.display='none'; Codehighlighter1_487_542_Open_Text.style.display='none'; Codehighlighter1_487_542_Closed_Image.style.display='inline'; Codehighlighter1_487_542_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" width="11" align="top" alt=""/><img id="Codehighlighter1_487_542_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_487_542_Closed_Text.style.display='none'; Codehighlighter1_487_542_Open_Image.style.display='inline'; Codehighlighter1_487_542_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" width="11" align="top" alt=""/>                </span><span id="Codehighlighter1_487_542_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" alt=""/></span><span id="Codehighlighter1_487_542_Open_Text"><span style="COLOR: #000000">{ <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                    </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.listBox1.Items.Add(</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">No MAC Address!</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">); <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" width="11" align="top" alt=""/>                }</span></span><span style="COLOR: #000000"> <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"> <br/><img id="Codehighlighter1_557_796_Open_Image" onclick="this.style.display='none'; Codehighlighter1_557_796_Open_Text.style.display='none'; Codehighlighter1_557_796_Closed_Image.style.display='inline'; Codehighlighter1_557_796_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" width="11" align="top" alt=""/><img id="Codehighlighter1_557_796_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_557_796_Closed_Text.style.display='none'; Codehighlighter1_557_796_Open_Image.style.display='inline'; Codehighlighter1_557_796_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" width="11" align="top" alt=""/>                </span><span id="Codehighlighter1_557_796_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" alt=""/></span><span id="Codehighlighter1_557_796_Open_Text"><span style="COLOR: #000000">{ <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                    </span><span style="COLOR: #0000ff">foreach</span><span style="COLOR: #000000">(System.Management.ManagementObject mymac </span><span style="COLOR: #0000ff">in</span><span style="COLOR: #000000"> msearch.Get()) <br/><img id="Codehighlighter1_636_790_Open_Image" onclick="this.style.display='none'; Codehighlighter1_636_790_Open_Text.style.display='none'; Codehighlighter1_636_790_Closed_Image.style.display='inline'; Codehighlighter1_636_790_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" width="11" align="top" alt=""/><img id="Codehighlighter1_636_790_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_636_790_Closed_Text.style.display='none'; Codehighlighter1_636_790_Open_Image.style.display='inline'; Codehighlighter1_636_790_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" width="11" align="top" alt=""/>                    </span><span id="Codehighlighter1_636_790_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" alt=""/></span><span id="Codehighlighter1_636_790_Open_Text"><span style="COLOR: #000000">{ <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                        </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> str1</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.Format(</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">MAC{0} address:{1}</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">,i.ToString(),mymac[</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">MACAddress</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">].ToString()); <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.listBox1.Items.Add(str1); <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                        i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">; <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" width="11" align="top" alt=""/>                    }</span></span><span style="COLOR: #000000"> <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" width="11" align="top" alt=""/>                }</span></span><span style="COLOR: #000000"> <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" width="11" align="top" alt=""/>            }</span></span><span style="COLOR: #000000"> <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>            </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000">(Exception ex) <br/><img id="Codehighlighter1_829_906_Open_Image" onclick="this.style.display='none'; Codehighlighter1_829_906_Open_Text.style.display='none'; Codehighlighter1_829_906_Closed_Image.style.display='inline'; Codehighlighter1_829_906_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" width="11" align="top" alt=""/><img id="Codehighlighter1_829_906_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_829_906_Closed_Text.style.display='none'; Codehighlighter1_829_906_Open_Image.style.display='inline'; Codehighlighter1_829_906_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" width="11" align="top" alt=""/>            </span><span id="Codehighlighter1_829_906_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" alt=""/></span><span id="Codehighlighter1_829_906_Open_Text"><span style="COLOR: #000000">{ <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> msg</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">ex.Message.ToString(); <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/>                MessageBox.Show(</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">erro</span><span style="COLOR: #000000">&#8220;</span><span style="COLOR: #000000">, msg); <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" width="11" align="top" alt=""/>            }</span></span><span style="COLOR: #000000"> <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" alt=""/> <br/><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" width="11" align="top" alt=""/>        }</span></span> </p>
<p><br/></p>
<p><center class="aTitle">WMI的应用 </center><br />
<table width="96%">
<tbody>
<tr>
<td><br/>来源：<span id="SourceLabel"> maqiaos_cn </span><br/>阅读：<span id="HitsLabel">1476</span> 次 <br/>日期：<span id="TimeLabel">2004-7-30</span> </td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="80%" align="center" border="0">
<tbody>
<tr>
<td>作  者：maqiaos_cn <br/>发表于：2003-1-16
<p>    WMI(Windows Management Instrumentation)技术是微软提供的Windows下的系统管理工具。 <br/>通过该工具可以在本地或者管理客户端系统中几乎一切的信息。很多专业的网络管理工具都是 <br/>基于WMI开发的。该工具在Win2000以及WinNT下是标准工具，在Win9X下是扩展安装选项。本文 <br/>将介绍如何通过VB编程来访问WMI对象的编程。 <br/><br/>   首先来看一个简单的通过WMI获取系统信息的范例，这个范例通过WMI对象获得系统中运行 <br/>的的进程： <br/><br/>Function Enum1() As String <br/>    Dim WMI <br/><br/>    Set WMI = GetObject(&#8221;WinMgmts:&#8221;) <br/>    Set objs = WMI.InstancesOf(&#8221;Win32_Process&#8221;) <br/><br/>    For Each obj In objs <br/>        Enum1 = Enum1 + obj.Description + Chr(13) + Chr(10) <br/>    Next <br/>End Function <br/><br/>    在上面的代码中，首先通过  GetObject(&#8221;WinMgmts:&#8221;)获得WMI对象，在WMI对象下有很多的 <br/>子项，在这里我们通过WMI.InstancesOf(&#8221;Win32_Process&#8221;)获得系统中所有的进程列表子项。 <br/><br/>    下面看一个完整的访问WMI对象的范例，这个范例获得计算机的信息。 <br/>    建立一个新工程，在Form1中添加一个TextBox控件以及一个CommandButton控件，在 <br/>CommandButton的Click事件中写入以下的代码： <br/><br/><br/>Private Sub Command1_Click() <br/>    Dim s, System, item <br/>    Dim i As Integer <br/><br/>    Set System = GetObject(&#8221;winmgmts:&#8221;).InstancesOf(&#8221;Win32_ComputerSystem&#8221;) <br/>    For Each item In System <br/>        ‘List1.AddItem item.cputype <br/>        s = &#8220;Computer Info&#8221; &amp; vbCrLf <br/>        s = s &amp; &#8220;***********************&#8221; &amp; vbCrLf <br/>        s = s &amp; &#8220;计算机名称: &#8221; &amp; item.name &amp; vbCrLf <br/>        s = s &amp; &#8220;状态: &#8221; &amp; item.Status &amp; vbCrLf <br/>        s = s &amp; &#8220;类型: &#8221; &amp; item.SystemType &amp; vbCrLf <br/>        s = s &amp; &#8220;生产厂家: &#8221; &amp; item.Manufacturer &amp; vbCrLf <br/>        s = s &amp; &#8220;型号: &#8221; &amp; item.Model &amp; vbCrLf <br/>        s = s &amp; &#8220;内存: ~&#8221; &amp; item.totalPhysicalMemory \ 1024000 &amp; &#8220;mb&#8221; &amp; vbCrLf <br/>        s = s &amp; &#8220;域: &#8221; &amp; item.domain &amp; vbCrLf <br/>        ‘s = s &amp; &#8220;工作组&#8221; &amp; item.Workgroup &amp; vbCrLf ‘获得工作组和域的选项不能同时用 <br/><br/>        s = s &amp; &#8220;当前用户: &#8221; &amp; item.username &amp; vbCrLf <br/>        s = s &amp; &#8220;启动状态&#8221; &amp; item.BootupState &amp; vbCrLf <br/>        s = s &amp; &#8220;该计算机属于&#8221; &amp; item.PrimaryOwnerName &amp; vbCrLf <br/>        s = s &amp; &#8220;系统类型&#8221; &amp; item.CreationClassName &amp; vbCrLf <br/>        s = s &amp; &#8220;计算机类类型&#8221; &amp; item.Description &amp; vbCrLf <br/><br/>        For i = 0 To 1  ‘这里假设安装了两个系统 <br/>            s = s &amp; Chr(5) &amp; &#8220;启动选项&#8221; &amp; i &amp; &#8221; :&#8221; &amp; item.SystemStartupOptions(i) _ <br/>                &amp; vbCrLf <br/>        Next i <br/>    Next <br/><br/>    Text1.Text = s <br/>End Sub <br/><br/>    运行程序，点击Command1，在textBox中就可以显示计算机的信息。 <br/><br/>    在上面的代码中，程序通过GetObject(&#8221;winmgmts:&#8221;)获得WMI对象，然后获得下面的 <br/>Win32_ComputerSystem子项并通过访问Win32_ComputerSystem对象中的分项获得系统中的信息。 <br/>需要说明的是，并不是所有的系统都支持WMI，在有些系统中无法显示生产厂家等信息。 <br/><br/>    现在的计算机以及网络组成十分复杂。例如系统硬件方面就有主板、硬盘、网卡&#8230; 。 <br/>软件方面有操作系统、系统中安装的软件、正在运行的进程等等。网络方面有域、工作组 <br/>等等。利用WMI可以访问上面的全部信息，但是如果向上面一样的利用分项来访问的话会很 <br/>麻烦。为此，WMI提供了一种类似SQL语句的查询语句，可以通过查询语句获得WMI对象下的子项。 <br/><br/>    下面是一个遍历系统中安装的网卡并返回网卡MAC地址的代码： <br/><br/>Private Function MACAddress() As String <br/><br/>   Set objs = GetObject(&#8221;winmgmts:&#8221;).ExecQuery( _ <br/>      &#8220;SELECT MACAddress &#8221; &amp; _ <br/>      &#8220;FROM Win32_NetworkAdapter &#8221; &amp; _ <br/>      &#8220;WHERE &#8221; &amp; _ <br/>      &#8220;((MACAddress Is Not NULL) &#8221; &amp; _ <br/>      &#8220;AND (Manufacturer &lt;&gt; &#8221; &amp; _ <br/>      &#8220;‘Microsoft‘))&#8221;) <br/><br/>   For Each obj In objs <br/>      MACAddress = obj.MACAddress <br/>      Exit For <br/>   Next obj <br/>End Function <br/><br/>    上面的代码获得WMI对象，然后运行ExecQuery执行一个WMI查询语句获得安装的网卡并返回 <br/>网卡的MAC地址。 <br/><br/>    WMI还支持事件处理，让程序可以处理系统事件，例如程序运行、关闭，可移动驱动器的插入、 <br/>取出等。下面是一个可以对系统中运行程序进行监控的程序。 <br/>    首先建立一个新工程，然后点击菜单的 project | references 项，在references列表中选中 <br/>Microsoft WMI Scripting Library将WMI对象库加入工程中。然后在Form1中加入一个ListBox控件， <br/>然后在Form1中加入以下代码： <br/><br/><br/>Option Explicit <br/><br/><br/>Dim Locator As SWbemLocator <br/>Dim Services As SWbemServices <br/>Dim WithEvents StatusSink As SWbemSink <br/><br/>Private Sub KillEvents() <br/>    StatusSink.Cancel <br/>    Set StatusSink = Nothing <br/>End Sub <br/><br/>Private Sub Form_Load() <br/>    Dim Query As String <br/><br/>    Set StatusSink = New SWbemSink <br/>    Set Locator = CreateObject(&#8221;WbemScripting.SWbemLocator&#8221;) <br/>    Set Services = Locator.ConnectServer() <br/><br/>    Query = &#8220;SELECT * FROM __InstanceCreationEvent &#8221; <br/>    Query = Query + &#8220;WITHIN 1 &#8221; <br/>    Query = Query + &#8220;WHERE TargetInstance ISA ‘Win32_Process‘&#8221; <br/><br/>    Services.ExecNotificationQueryAsync StatusSink, Query <br/>End Sub <br/><br/><br/>Private Sub StatusSink_OnObjectReady(ByVal StatusEvent As SWbemObject, _ <br/>                                     ByVal EventContext As SWbemNamedValueSet) <br/><br/>    Dim arr <br/>    Dim strQue As String <br/>    Dim i As Integer <br/><br/>    List1.Clear <br/>    arr = Split(StatusEvent.GetObjectText_, Chr(10)) <br/>    For i = LBound(arr) To UBound(arr) <br/>        List1.AddItem arr(i) <br/>    Next i <br/>End Sub <br/><br/><br/>Private Sub StatusSink_OnCompleted(ByVal HResult As WbemErrorEnum, _ <br/>                                   ByVal ErrorObject As SWbemObject, _ <br/>                                   ByVal EventContext As SWbemNamedValueSet) <br/><br/>    If HResult &lt;&gt; wbemErrCallCancelled Then <br/>        ‘错误处理 <br/>    End If <br/>End Sub <br/><br/><br/><br/>    在上面的程序中定义了一个SWbemSink对象StatusSink，然后建立一个SWbemServices对象Server， <br/>并将StatusSink连接到Server对象上。这样就可以通过StatusSink监控程序的运行。 <br/>    运行程序，然后任意运行一个程序，在Form1的ListBox中就可以列出运行的程序的信息。 <br/><br/>    WMI应用最强大的一面是可以通过WEB页面来实现远程管理。下面我们来建立一个HTML页面，该页面 <br/>可以实现向上面的VB程序一样动态监控系统中运行的程序。监控系统中程序运行的HTML代码如下： <br/><br/><br/>&lt;html&gt; <br/>&lt;head&gt; <br/>&lt;object ID=&#8221;mysink&#8221; CLASSID= <br/>&#8220;CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223&#8243;&gt;&lt;/object&gt; <br/>&lt;/head&gt; <br/>&lt;SCRIPT&gt; <br/>function window.onload() <br/>{ <br/>  var locator = new ActiveXObject (&#8221;WbemScripting.SWbemLocator&#8221;); <br/>  var service = locator.ConnectServer(); <br/>  szQuery = &#8220;SELECT * FROM __InstanceCreationEvent &#8220;; <br/>  szQuery += &#8220;WITHIN 1 &#8220;; <br/>  szQuery += &#8220;WHERE TargetInstance ISA ‘Win32_Process‘&#8221;; <br/>  service.ExecNotificationQueryAsync(mysink,szQuery); <br/>} <br/>&lt;/SCRIPT&gt; <br/>&lt;script FOR=&#8221;mysink&#8221; EVENT=&#8221;OnObjectReady(obj, objAsyncContext)&#8221;&gt; <br/>  document.all.info.innerHTML += obj.TargetInstance.Name + &#8220;&lt;br&gt;&#8221;; <br/>&lt;/script&gt; <br/>&lt;body&gt; <br/>&lt;span ID=&#8221;info&#8221;&gt;&lt;/span&gt; <br/>&lt;/body&gt; <br/>&lt;/html&gt; <br/><br/><br/>    保存代码为Htm后缀的页面文件。双击打开网页，然后运行一个程序，在网页上就可以列出 <br/>运行的程序的文件名。 <br/><br/>    以上简要的介绍了一下WMI的应用，实际上WMI对象的操作是十分复杂，功能也是很强大的，例如 <br/>你可以通过WMI在服务器上监控整个局域网上的计算机、向局域网上的计算机批量安装软件（例如杀 <br/>毒软件）。通过页面远程访问服务器，控件服务器运行程序，添加用户等。关于更多的WMI的应用， <br/>读者可以访问MSDN上WMI开发的主页: <br/><br/>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmistart_5kth.asp <br/><br/>获取更多信息。 <br/><br/><br/><br/>    以上程序在Win2000专业版下编写。</p>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2005/01/26/257685.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>巧妙突破Win 2003系统的种种限制</title>
		<link>http://blog.donews.com/skyfei/archive/2004/12/20/208567.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2004/12/20/208567.aspx#comments</comments>
		<pubDate>Mon, 20 Dec 2004 05:03:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2004/12/20/208567.aspx</guid>
		<description><![CDATA[巧妙突破Win 2003系统的种种限制 
 
2004-12-20 09:26　 作者：天极yesky 青人　  
]]></description>
			<content:encoded><![CDATA[<p>　一、自动登录不求人 <br/><br/>　　和Windows 2000 Server一样，Windows Server 2003进入系统时也要求同时按下“Ctrl+Alt+Del”组合键,然后输入用户名和密码，才能登录。在这里我们可以通过设置让它自动登录，方法就是照搬笔者在Windows 2000上曾经使用过的方法，按下“WIN+R”组合键，打开“运行”对话框，输入“regedit”,按确定后会弹出熟悉的注册表编辑器。打开“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows_NT\CurrentVersion\Winlogon”分支，新建字符串值AutoAdminLogon，将该项的值设为1，再新建字符串值DefaultPass<a class="article" href="http://www.enet.com.cn/eschool/includes/zhuanti/zt/office/9.shtml" target="_blank">word</a>，将该项设为你的管理员密码。这样就一切OK了。 </p>
<p>或者用命令行：control userpasswords2</p>
<p/>
<p>四、谁说不能CS <br/><br/>　　很多CS玩家抱怨Windows Server 2003中CS游戏不能玩，这是因为Windows Server 2003中默认禁用了声音服务，以及<a class="article" href="http://www.enet.com.cn/eschool/includes/zhuanti/zt/direct/15.shtml" target="_blank"><font color="#002c99">DirectX</font></a>加速，我们可以把它们一一开启。首先打开“服务”窗口，找到并双击“Windows Audio”，将它设置为自动。然后在<a class="article" href="http://www.enet.com.cn/eschool/includes/zhuanti/zm/index.shtml" target="_blank"><font color="#002c99">桌面</font></a>上单击右键，选择“属性→设置→高级→疑难解答”，将其中的“<a class="article" href="http://www.enet.com.cn/ediy" target="_blank"><font color="#002c99">硬件</font></a>加速”滚动条拖到最右侧。最后打开“运行”对话框，输入dxdiag，确定后弹出“DirectX诊断工具，进入“显示”页面，分别点击DirectDraw、Direct3D和AGPTexture三个按钮启用加速。　　 <br/><br/>　　五、我想关机就关机 <br/><br/>　　Windows Server 2003中关机是需要“充分”理由的，要取消它很容易。按下“WIN+R”组合键，打开“运行”对话框，输入gpedit.msc，打开“<a class="article" href="http://www.enet.com.cn/eschool/inforcenter/T20040413302018.html" target="_blank"><font color="#002c99">组策略</font></a>编辑器”，选择“本地计算机策略→计算机配置→管理模板→系统”，接着双击右侧窗口中的“显示关闭事件跟踪程序”，最后在“设置”选项卡中“已禁用”即可。 <br/><br/>　　这些设置完后，你就可以尽情地享受Windows Server 2003给你带来的快乐了。 <br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2004/12/20/208567.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++基本功：全面掌握const、volatile和mutable关键字</title>
		<link>http://blog.donews.com/skyfei/archive/2004/12/17/205506.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2004/12/17/205506.aspx#comments</comments>
		<pubDate>Fri, 17 Dec 2004 03:29:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[c/c++ 技术文章网络收藏]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2004/12/17/205506.aspx</guid>
		<description><![CDATA[摘自：
http://dev.csdn.net/develop/article/17/17606.shtm]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'"><strong>CONST</strong></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">一</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">一般应用</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">1.const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰各种变量的用法</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>   a.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">取代</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">define<br/>     #define D_INT 100<br/>     #define D_LONG 100.29<br/>     ………<br/>     const int D_INT = 100;<br/>     const D_INT = 100;     //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如果定义的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">int</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">类型</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">可省略</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">int.<br/>     const long D_LONG = 100.29;<br/>     ………<br/>     const int&amp; a = 100; <br/>     const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">替代</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">define</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">虽然增加分配空间</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">可它却保证了类型安全</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">在</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">C</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">标准中</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">定义的数据相当于全局的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">而</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">C++</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">中视声明的位置而定</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>   b.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰指针相关的变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">以三组简单的定义示意：</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     Group1:   <br/>     int a = 0;    <br/>     const int* b = &amp;a;&#8212;&#8212;&#8212;&#8212;  [1]                <br/>     int const *b = &amp;a;&#8212;&#8212;&#8212;&#8212;  [2]                     <br/>     const int* const b = &amp;a;&#8212;- [4]   <br/>          <br/>     Group2:  <br/>     const char *p = &#8220;const&#8221;;&#8212;&#8212;&#8212;&#8212;&#8211;[1] <br/>     char const *p = &#8220;const&#8221;;&#8212;&#8212;&#8212;&#8212;&#8211;[2]   <br/>     char* const p = &#8220;const&#8221;;&#8212;&#8212;&#8212;&#8212;&#8211;[3]   <br/>     const char * const p = &#8220;const&#8221;;&#8212;-[4]      <br/>     <br/>     Group3:<br/>      int a=0;<br/>        const int &amp;b = a;&#8212;&#8212;&#8212;&#8212;&#8212;[1]<br/>     int const &amp;b = a;&#8212;&#8212;&#8212;&#8212;&#8212;[2]  <br/>     int &amp; const b = a;&#8212;&#8212;&#8212;&#8212;&#8211;[3]  //&#8212;&gt;</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰引用时</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">被忽略</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     const int &amp; const b = a;&#8212;&#8211;[4]<br/>     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">总结：</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     1.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如果</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">位于星号左侧</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">则</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">用来修饰指针所指向的变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,<br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">即指针指向的为不可变的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>     2.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如果</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">位于星号右侧</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">就是修饰指针本身</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">即指针本身是</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">不可变的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">因此</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,[1]</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">[2]</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">的情况相同</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">指针所指向内容不可变</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">(const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">放在变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">声明符的位置无关</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">),<br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">这种情况下不允许对内容进行更改</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如不能</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">*a = 3 ;<br/>     3.[3]</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">中指针本身是不可变的，而指针所指向的内容是可变的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">这种情况</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">下不能对指针本身</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">进行更改操作</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">a++</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">是错误的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     4.[4]</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">中指针本身和指向的内容均为常量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.(</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">引用特殊：引用在使用增加</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">遇义时</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">增加它代表的变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">所以</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">qualifiers on reference are ignoredv.<br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">延伸点</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">: <br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">注意示例</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">:<br/>       1.const int&amp; reference = 1000; <br/>       2.char* p = &#8220;const&#8221;<br/>         char*&amp; q ;<br/>   <br/>2.const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">在函数环境下的各种应用</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">常用法示例如下：</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   const A&amp;  _Fun(const  A&amp; _in);  //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰引用型传入参数</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   // A  _Fun(const A&amp; _in);<br/>   //A&amp; _Fun(const A&amp; _in);<br/>   //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">上面的两种</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">在函数内部有特殊的步骤</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">这里不详提了…</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">..<br/>  <br/>   const  A*  _Fun( const  A* _in);   //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰指针型传入参数</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   void _Fun( ) const;   //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">class</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">成员函数</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   const  A&amp;  _Fun(A&amp; _in );  //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰返回值</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   const A &amp; operator(const A&amp; _in);  //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">同时修饰传入参数和返回值</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p/></span></p>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">   a.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰参数</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">void _Fun(const A* _in)</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">或</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman"> void _Fun(const A&amp; _in);<br/>     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">它们被修饰后</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">在函数执行期间行为特性同于上面的讲解</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,<br/>     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">注意：这不会改变原来数据的是否是</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">的属性</span><font face="Times New Roman"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial">.</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p/></span></font></p>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">   b.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰函数返回值</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    const A&amp;  _Fun( )<br/>    const A*   _Fun( );<br/>    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">注意：由于生命期不同步的问题</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">不可将局部的变量的指针或引用返回</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">(static</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">除外</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">).<br/>    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">另外</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">传出来的视情况</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">代表不同的意思…</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">对于</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">A&amp;</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">返回类型</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">你若将之赋与其它变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">那么它实际执行的是将返回的变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    (</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">或引用</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">)</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">代表的数据赋出</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">..</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">而你若将其它值赋予之</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">那么被赋予的是变量或引</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">用代表的数据</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">. </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">而</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const A&amp; </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">一般是防止之做为左值被赋值</span><font face="Times New Roman"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial">.</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p/></span></font></p>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">这个地方还有很多的细节问题</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">(</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">譬如在连续赋值、返回的临时对象的处理、</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">重载的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">和非</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">cosnt</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">运算符等等</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">),</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">读者自己在实践中需要多多总结</span><font face="Times New Roman"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial">.</span></font></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><font face="Times New Roman"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><font color="#000000"><span class="h2"><strong>使用可变（mutable）成员隐藏实现细节</strong></span> <br/><br/></font><span class="hui"><font color="#000000">作者： </font><font color="#0000ff">Builder.com</font></span></p>
<p></span>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><font face="Times New Roman" color="#000000"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><span class="hui">键字 mutable 是一个奇怪的修饰符（specifier），它只能够用于一个类的非静态数据成员。下面我将讨论 mutable 的语义和用法，但是首先我要解释一下 C++ 对象模型的一个关键概念。</span></p>
<p></span></font></p>
<p><span class="hui">键字 mutable 是一个奇怪的修饰符（specifier），它只能够用于一个类的非静态数据成员。下面我将讨论 mutable 的语义和用法，但是首先我要解释一下 C++ 对象模型的一个关键概念。</span></p>
<p/><font face="Times New Roman" color="#000000"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><span class="hui"><br />
<h5>对象的状态</h5>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"/>
<p>一个对象的状态由其非静态数据成员的值构成，因此，修改一个数据成员将会改变整个对象的状态。将一个成员函数声明为 const 能够保证它不会改变对象的状态。</p>
<p>然而在一些情况下，对象的逻辑状态与基物理状态之间可能有差别。例如，对于一个表示绘画图像的对象就存在这种情况。如果图像还没有更改，那么我们就认为其状态没有发生变化。然而，从底层实现方面来说，如果大对象在一段时间没有活动，那么它们的内存通常会被交换到一个文件中。交换一个图像并不会真地影响其状态，但是对象的一些数据成员可能会发生变化，在这里可能会发生变化的是指针、标志位等。</p>
<p>在用户调用一个诸如 Redraw() 之类的 const 成员函数时，他们并不关心这个函数在内部是如何实现的。从他们的角度来说，这个函数并不改变对象的逻辑状态，因此被声明为 const。Redraw() 有可能修改对象的物理状态这一事实是一个他们不应该关心的实现细节。例如：</p>
<p>int Image::Redraw() const<br/>{<br/> if (isLoaded==false)<br/> {<br/>  //..read image data from a disk into a local buffer<br/>  isLoaded=true; //changing a data member&#8217;s value<br/> }<br/>  //..paint image in the screen<br/>} </p>
<p>class Image<br/></p>
<h5>可变（mutable）数据成员</h5>
<p>如果尝试编译这段代码，你会得到一个编译错误。虽然 Redraw() 声明为 const，但是它修改了一个数据成员。解决这个编译错误的方法是将 isLoaded 声明为一个 mutable 数据成员：</p>
<p>class Image<br/>{<br/>public:<br/> int Redraw() const;<br/> //..<br/>private:<br/> mutable bool isLoaded;//can be changed by a const function<br/>}; </p>
<p>不像普通的数据成员，const 成员函数可以修改 mutable 数据成员。</p>
<p>Mutable 数据成员的使用看上去像是骗术，因为它能够使 const 函数修改对象的数据成员。然而，明智地使用 mutable 关键字可以提高代码质量，因为它能够让你向用户隐藏实现细节，而无须使用不确定的东西，比如 const_cast&lt;&gt;。</p>
<p></span></p>
<h5>对象的状态</h5>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"/>
<p>一个对象的状态由其非静态数据成员的值构成，因此，修改一个数据成员将会改变整个对象的状态。将一个成员函数声明为 const 能够保证它不会改变对象的状态。</p>
<p>然而在一些情况下，对象的逻辑状态与基物理状态之间可能有差别。例如，对于一个表示绘画图像的对象就存在这种情况。如果图像还没有更改，那么我们就认为其状态没有发生变化。然而，从底层实现方面来说，如果大对象在一段时间没有活动，那么它们的内存通常会被交换到一个文件中。交换一个图像并不会真地影响其状态，但是对象的一些数据成员可能会发生变化，在这里可能会发生变化的是指针、标志位等。</p>
<p>在用户调用一个诸如 Redraw() 之类的 const 成员函数时，他们并不关心这个函数在内部是如何实现的。从他们的角度来说，这个函数并不改变对象的逻辑状态，因此被声明为 const。Redraw() 有可能修改对象的物理状态这一事实是一个他们不应该关心的实现细节。例如：</p>
<p>int Image::Redraw() const<br/>{<br/> if (isLoaded==false)<br/> {<br/>  //..read image data from a disk into a local buffer<br/>  isLoaded=true; //changing a data member&#8217;s value<br/> }<br/>  //..paint image in the screen<br/>} </p>
<p>class Image<br/></p>
<h5>可变（mutable）数据成员</h5>
<p>如果尝试编译这段代码，你会得到一个编译错误。虽然 Redraw() 声明为 const，但是它修改了一个数据成员。解决这个编译错误的方法是将 isLoaded 声明为一个 mutable 数据成员：</p>
<p>class Image<br/>{<br/>public:<br/> int Redraw() const;<br/> //..<br/>private:<br/> mutable bool isLoaded;//can be changed by a const function<br/>}; </p>
<p>不像普通的数据成员，const 成员函数可以修改 mutable 数据成员。</p>
<p>Mutable 数据成员的使用看上去像是骗术，因为它能够使 const 函数修改对象的数据成员。然而，明智地使用 mutable 关键字可以提高代码质量，因为它能够让你向用户隐藏实现细节，而无须使用不确定的东西，比如 const_cast&lt;&gt;。</p>
<p>volatile关键字</p>
<p>　　volatile是c/c++中一个鲜为人知的关键字,该关键字告诉编译器不要持有变量的临时拷贝,它可以适用于基础类型<br/>　　如：int,char,long&#8230;&#8230;也适用于C的结构和C++的类。当对结构或者类对象使用volatile修饰的时候，结构或者<br/>　　类的所有成员都会被视为volatile.</p>
<p>　　使用volatile并不会否定对CRITICAL_SECTION,Mutex,Event等同步对象的需要<br/>　　例如：<br/>　　int i;<br/>　　i = i + 3;<br/>　　无论如何，总是会有一小段时间，i会被放在一个寄存器中，因为算术运算只能在寄存器中进行。一般来说，volatitle<br/>　　关键字适用于行与行之间，而不是放在行内。</p>
<p>　　我们先来实现一个简单的函数，来观察一下由编译器产生出来的汇编代码中的不足之处，并观察volatile关键字如何修正<br/>　　这个不足之处。在这个函数体内存在一个busy loop(所谓busy loop也叫做busy waits,是一种高度浪费CPU时间的循环方法)</p>
<p>
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　oid getKey(char* pch)<br/>　　{<br/>　　while (*pch == 0)<br/>　　;<br/>　　}</td>
</tr>
</tbody>
</table>
<p>　　当你在VC开发环境中将最优化选项都关闭之后，编译这个程序，将获得以下结果(汇编代码)<br/><br/><br />
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　　;       while (*pch == 0)<br/>　　$L27<br/>　　; Load the address stored in pch<br/>　　mov eax, DWORD PTR _pch$[ebp]<br/>　　; Load the character into the EAX register<br/>　　movsx eax, BYTE PTR [eax]<br/>　　; Compare the value to zero<br/>　　test eax, eax<br/>　　; If not zero, exit loop<br/>　　jne $L28<br/>　　;<br/>　　jmp $L27<br/>　　$L28<br/>　　;}</td>
</tr>
</tbody>
</table>
<p>　　这段没有优化的代码不断的载入适当的地址，载入地址中的内容，测试结果。效率相当的低，但是结果非常准确</p>
<p>　　现在我们再来看看将编译器的所有最优化选项开关都打开以后，重新编译程序，生成的汇编代码，和上面的代码<br/><br/>　　比较一下有什么不同<br/><br/><br />
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　　;{ <br/>　　; Load the address stored in pch<br/>　　mov eax, DWORD PTR _pch$[esp-4]<br/>　　; Load the character into the AL register<br/>　　movsx al, BYTE PTR [eax]<br/>　　; while (*pch == 0)<br/>　　; Compare the value in the AL register to zero<br/>　　test al, al<br/>　　; If still zero, try again<br/>　　je SHORT $L84<br/>　　;<br/>　　;}</td>
</tr>
</tbody>
</table>
<p><br/><br clear="all"/></p>
<p></span></font></span></font></p>
<p><font color="#000000"><span class="h2"><strong>使用可变（mutable）成员隐藏实现细节</strong></span> <br/><br/></font><span class="hui"><font color="#000000">作者： </font><font color="#0000ff">Builder.com</font></span></p>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><font face="Times New Roman" color="#000000"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><span class="hui">键字 mutable 是一个奇怪的修饰符（specifier），它只能够用于一个类的非静态数据成员。下面我将讨论 mutable 的语义和用法，但是首先我要解释一下 C++ 对象模型的一个关键概念。</span></p>
<p></span></font></p>
<p><span class="hui">键字 mutable 是一个奇怪的修饰符（specifier），它只能够用于一个类的非静态数据成员。下面我将讨论 mutable 的语义和用法，但是首先我要解释一下 C++ 对象模型的一个关键概念。</span></p>
<p/><font face="Times New Roman" color="#000000"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><span class="hui"><br />
<h5>对象的状态</h5>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"/>
<p>一个对象的状态由其非静态数据成员的值构成，因此，修改一个数据成员将会改变整个对象的状态。将一个成员函数声明为 const 能够保证它不会改变对象的状态。</p>
<p>然而在一些情况下，对象的逻辑状态与基物理状态之间可能有差别。例如，对于一个表示绘画图像的对象就存在这种情况。如果图像还没有更改，那么我们就认为其状态没有发生变化。然而，从底层实现方面来说，如果大对象在一段时间没有活动，那么它们的内存通常会被交换到一个文件中。交换一个图像并不会真地影响其状态，但是对象的一些数据成员可能会发生变化，在这里可能会发生变化的是指针、标志位等。</p>
<p>在用户调用一个诸如 Redraw() 之类的 const 成员函数时，他们并不关心这个函数在内部是如何实现的。从他们的角度来说，这个函数并不改变对象的逻辑状态，因此被声明为 const。Redraw() 有可能修改对象的物理状态这一事实是一个他们不应该关心的实现细节。例如：</p>
<p>int Image::Redraw() const<br/>{<br/> if (isLoaded==false)<br/> {<br/>  //..read image data from a disk into a local buffer<br/>  isLoaded=true; //changing a data member&#8217;s value<br/> }<br/>  //..paint image in the screen<br/>} </p>
<p>class Image<br/></p>
<h5>可变（mutable）数据成员</h5>
<p>如果尝试编译这段代码，你会得到一个编译错误。虽然 Redraw() 声明为 const，但是它修改了一个数据成员。解决这个编译错误的方法是将 isLoaded 声明为一个 mutable 数据成员：</p>
<p>class Image<br/>{<br/>public:<br/> int Redraw() const;<br/> //..<br/>private:<br/> mutable bool isLoaded;//can be changed by a const function<br/>}; </p>
<p>不像普通的数据成员，const 成员函数可以修改 mutable 数据成员。</p>
<p>Mutable 数据成员的使用看上去像是骗术，因为它能够使 const 函数修改对象的数据成员。然而，明智地使用 mutable 关键字可以提高代码质量，因为它能够让你向用户隐藏实现细节，而无须使用不确定的东西，比如 const_cast&lt;&gt;。</p>
<p></span></p>
<h5>对象的状态</h5>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"/>
<p>一个对象的状态由其非静态数据成员的值构成，因此，修改一个数据成员将会改变整个对象的状态。将一个成员函数声明为 const 能够保证它不会改变对象的状态。</p>
<p>然而在一些情况下，对象的逻辑状态与基物理状态之间可能有差别。例如，对于一个表示绘画图像的对象就存在这种情况。如果图像还没有更改，那么我们就认为其状态没有发生变化。然而，从底层实现方面来说，如果大对象在一段时间没有活动，那么它们的内存通常会被交换到一个文件中。交换一个图像并不会真地影响其状态，但是对象的一些数据成员可能会发生变化，在这里可能会发生变化的是指针、标志位等。</p>
<p>在用户调用一个诸如 Redraw() 之类的 const 成员函数时，他们并不关心这个函数在内部是如何实现的。从他们的角度来说，这个函数并不改变对象的逻辑状态，因此被声明为 const。Redraw() 有可能修改对象的物理状态这一事实是一个他们不应该关心的实现细节。例如：</p>
<p>int Image::Redraw() const<br/>{<br/> if (isLoaded==false)<br/> {<br/>  //..read image data from a disk into a local buffer<br/>  isLoaded=true; //changing a data member&#8217;s value<br/> }<br/>  //..paint image in the screen<br/>} </p>
<p>class Image<br/></p>
<h5>可变（mutable）数据成员</h5>
<p>如果尝试编译这段代码，你会得到一个编译错误。虽然 Redraw() 声明为 const，但是它修改了一个数据成员。解决这个编译错误的方法是将 isLoaded 声明为一个 mutable 数据成员：</p>
<p>class Image<br/>{<br/>public:<br/> int Redraw() const;<br/> //..<br/>private:<br/> mutable bool isLoaded;//can be changed by a const function<br/>}; </p>
<p>不像普通的数据成员，const 成员函数可以修改 mutable 数据成员。</p>
<p>Mutable 数据成员的使用看上去像是骗术，因为它能够使 const 函数修改对象的数据成员。然而，明智地使用 mutable 关键字可以提高代码质量，因为它能够让你向用户隐藏实现细节，而无须使用不确定的东西，比如 const_cast&lt;&gt;。</p>
<p>volatile关键字</p>
<p>　　volatile是c/c++中一个鲜为人知的关键字,该关键字告诉编译器不要持有变量的临时拷贝,它可以适用于基础类型<br/>　　如：int,char,long&#8230;&#8230;也适用于C的结构和C++的类。当对结构或者类对象使用volatile修饰的时候，结构或者<br/>　　类的所有成员都会被视为volatile.</p>
<p>　　使用volatile并不会否定对CRITICAL_SECTION,Mutex,Event等同步对象的需要<br/>　　例如：<br/>　　int i;<br/>　　i = i + 3;<br/>　　无论如何，总是会有一小段时间，i会被放在一个寄存器中，因为算术运算只能在寄存器中进行。一般来说，volatitle<br/>　　关键字适用于行与行之间，而不是放在行内。</p>
<p>　　我们先来实现一个简单的函数，来观察一下由编译器产生出来的汇编代码中的不足之处，并观察volatile关键字如何修正<br/>　　这个不足之处。在这个函数体内存在一个busy loop(所谓busy loop也叫做busy waits,是一种高度浪费CPU时间的循环方法)</p>
<p>
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　oid getKey(char* pch)<br/>　　{<br/>　　while (*pch == 0)<br/>　　;<br/>　　}</td>
</tr>
</tbody>
</table>
<p>　　当你在VC开发环境中将最优化选项都关闭之后，编译这个程序，将获得以下结果(汇编代码)<br/><br/><br />
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　　;       while (*pch == 0)<br/>　　$L27<br/>　　; Load the address stored in pch<br/>　　mov eax, DWORD PTR _pch$[ebp]<br/>　　; Load the character into the EAX register<br/>　　movsx eax, BYTE PTR [eax]<br/>　　; Compare the value to zero<br/>　　test eax, eax<br/>　　; If not zero, exit loop<br/>　　jne $L28<br/>　　;<br/>　　jmp $L27<br/>　　$L28<br/>　　;}</td>
</tr>
</tbody>
</table>
<p>　　这段没有优化的代码不断的载入适当的地址，载入地址中的内容，测试结果。效率相当的低，但是结果非常准确</p>
<p>　　现在我们再来看看将编译器的所有最优化选项开关都打开以后，重新编译程序，生成的汇编代码，和上面的代码<br/><br/>　　比较一下有什么不同<br/><br/><br />
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　　;{ <br/>　　; Load the address stored in pch<br/>　　mov eax, DWORD PTR _pch$[esp-4]<br/>　　; Load the character into the AL register<br/>　　movsx al, BYTE PTR [eax]<br/>　　; while (*pch == 0)<br/>　　; Compare the value in the AL register to zero<br/>　　test al, al<br/>　　; If still zero, try again<br/>　　je SHORT $L84<br/>　　;<br/>　　;}</td>
</tr>
</tbody>
</table>
<p><br/><br clear="all"/></p>
<p></span></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">一</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">一般应用</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">1.const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰各种变量的用法</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>   a.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">取代</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">define<br/>     #define D_INT 100<br/>     #define D_LONG 100.29<br/>     ………<br/>     const int D_INT = 100;<br/>     const D_INT = 100;     //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如果定义的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">int</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">类型</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">可省略</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">int.<br/>     const long D_LONG = 100.29;<br/>     ………<br/>     const int&amp; a = 100; <br/>     const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">替代</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">define</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">虽然增加分配空间</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">可它却保证了类型安全</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">在</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">C</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">标准中</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">定义的数据相当于全局的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">而</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">C++</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">中视声明的位置而定</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>   b.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰指针相关的变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">以三组简单的定义示意：</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     Group1:   <br/>     int a = 0;    <br/>     const int* b = &amp;a;&#8212;&#8212;&#8212;&#8212;  [1]                <br/>     int const *b = &amp;a;&#8212;&#8212;&#8212;&#8212;  [2]                     <br/>     const int* const b = &amp;a;&#8212;- [4]   <br/>          <br/>     Group2:  <br/>     const char *p = &#8220;const&#8221;;&#8212;&#8212;&#8212;&#8212;&#8211;[1] <br/>     char const *p = &#8220;const&#8221;;&#8212;&#8212;&#8212;&#8212;&#8211;[2]   <br/>     char* const p = &#8220;const&#8221;;&#8212;&#8212;&#8212;&#8212;&#8211;[3]   <br/>     const char * const p = &#8220;const&#8221;;&#8212;-[4]      <br/>     <br/>     Group3:<br/>      int a=0;<br/>        const int &amp;b = a;&#8212;&#8212;&#8212;&#8212;&#8212;[1]<br/>     int const &amp;b = a;&#8212;&#8212;&#8212;&#8212;&#8212;[2]  <br/>     int &amp; const b = a;&#8212;&#8212;&#8212;&#8212;&#8211;[3]  //&#8212;&gt;</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰引用时</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">被忽略</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     const int &amp; const b = a;&#8212;&#8211;[4]<br/>     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">总结：</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     1.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如果</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">位于星号左侧</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">则</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">用来修饰指针所指向的变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,<br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">即指针指向的为不可变的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>     2.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如果</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">位于星号右侧</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">就是修饰指针本身</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">即指针本身是</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">不可变的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.<br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">因此</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,[1]</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">和</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">[2]</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">的情况相同</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">指针所指向内容不可变</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">(const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">放在变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">声明符的位置无关</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">),<br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">这种情况下不允许对内容进行更改</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如不能</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">*a = 3 ;<br/>     3.[3]</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">中指针本身是不可变的，而指针所指向的内容是可变的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">这种情况</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">下不能对指针本身</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">进行更改操作</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">a++</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">是错误的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     4.[4]</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">中指针本身和指向的内容均为常量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.(</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">引用特殊：引用在使用增加</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">遇义时</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">增加它代表的变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">所以</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">qualifiers on reference are ignoredv.<br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">延伸点</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">: <br/>       </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">注意示例</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">:<br/>       1.const int&amp; reference = 1000; <br/>       2.char* p = &#8220;const&#8221;<br/>         char*&amp; q ;<br/>   <br/>2.const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">在函数环境下的各种应用</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">常用法示例如下：</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   const A&amp;  _Fun(const  A&amp; _in);  //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰引用型传入参数</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   // A  _Fun(const A&amp; _in);<br/>   //A&amp; _Fun(const A&amp; _in);<br/>   //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">上面的两种</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">在函数内部有特殊的步骤</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">这里不详提了…</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">..<br/>  <br/>   const  A*  _Fun( const  A* _in);   //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰指针型传入参数</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   void _Fun( ) const;   //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">class</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">成员函数</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   const  A&amp;  _Fun(A&amp; _in );  //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰返回值</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">   const A &amp; operator(const A&amp; _in);  //</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">同时修饰传入参数和返回值</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p/></span></p>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">   a.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰参数</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">如</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">void _Fun(const A* _in)</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">或</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman"> void _Fun(const A&amp; _in);<br/>     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">它们被修饰后</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">在函数执行期间行为特性同于上面的讲解</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,<br/>     </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">注意：这不会改变原来数据的是否是</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">的属性</span><font face="Times New Roman"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial">.</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p/></span></font></p>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">   b.</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">修饰函数返回值</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    const A&amp;  _Fun( )<br/>    const A*   _Fun( );<br/>    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">注意：由于生命期不同步的问题</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">不可将局部的变量的指针或引用返回</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">(static</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">除外</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">).<br/>    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">另外</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">传出来的视情况</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">代表不同的意思…</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">对于</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">A&amp;</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">返回类型</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">你若将之赋与其它变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">那么它实际执行的是将返回的变量</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    (</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">或引用</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">)</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">代表的数据赋出</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">..</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">而你若将其它值赋予之</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">,</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">那么被赋予的是变量或引</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">用代表的数据</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">. </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">而</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const A&amp; </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">一般是防止之做为左值被赋值</span><font face="Times New Roman"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial">.</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p/></span></font></p>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">这个地方还有很多的细节问题</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">(</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">譬如在连续赋值、返回的临时对象的处理、</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><br/><font face="Times New Roman">    </font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">重载的</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">const</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">和非</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">cosnt</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">运算符等等</span><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><font face="Times New Roman">),</font></span><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 新宋体; mso-ascii-font-family: 'Times New Roman'; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial; mso-hansi-font-family: 'Times New Roman'">读者自己在实践中需要多多总结</span><font face="Times New Roman"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial">.</span></font></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><font face="Times New Roman"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; mso-fareast-font-family: 新宋体; mso-bidi-font-size: 9.0pt; mso-bidi-font-family: Arial"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><font color="#000000"><span class="h2"><strong>使用可变（mutable）成员隐藏实现细节</strong></span> <br/><br/></font><span class="hui"><font color="#000000">作者： </font><font color="#0000ff">Builder.com</font></span></p>
<p></span>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><font face="Times New Roman" color="#000000"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><span class="hui">键字 mutable 是一个奇怪的修饰符（specifier），它只能够用于一个类的非静态数据成员。下面我将讨论 mutable 的语义和用法，但是首先我要解释一下 C++ 对象模型的一个关键概念。</span></p>
<p></span></font></p>
<p><span class="hui">键字 mutable 是一个奇怪的修饰符（specifier），它只能够用于一个类的非静态数据成员。下面我将讨论 mutable 的语义和用法，但是首先我要解释一下 C++ 对象模型的一个关键概念。</span></p>
<p/><font face="Times New Roman" color="#000000"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><span class="hui"><br />
<h5>对象的状态</h5>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"/>
<p>一个对象的状态由其非静态数据成员的值构成，因此，修改一个数据成员将会改变整个对象的状态。将一个成员函数声明为 const 能够保证它不会改变对象的状态。</p>
<p>然而在一些情况下，对象的逻辑状态与基物理状态之间可能有差别。例如，对于一个表示绘画图像的对象就存在这种情况。如果图像还没有更改，那么我们就认为其状态没有发生变化。然而，从底层实现方面来说，如果大对象在一段时间没有活动，那么它们的内存通常会被交换到一个文件中。交换一个图像并不会真地影响其状态，但是对象的一些数据成员可能会发生变化，在这里可能会发生变化的是指针、标志位等。</p>
<p>在用户调用一个诸如 Redraw() 之类的 const 成员函数时，他们并不关心这个函数在内部是如何实现的。从他们的角度来说，这个函数并不改变对象的逻辑状态，因此被声明为 const。Redraw() 有可能修改对象的物理状态这一事实是一个他们不应该关心的实现细节。例如：</p>
<p>int Image::Redraw() const<br/>{<br/> if (isLoaded==false)<br/> {<br/>  //..read image data from a disk into a local buffer<br/>  isLoaded=true; //changing a data member&#8217;s value<br/> }<br/>  //..paint image in the screen<br/>} </p>
<p>class Image<br/></p>
<h5>可变（mutable）数据成员</h5>
<p>如果尝试编译这段代码，你会得到一个编译错误。虽然 Redraw() 声明为 const，但是它修改了一个数据成员。解决这个编译错误的方法是将 isLoaded 声明为一个 mutable 数据成员：</p>
<p>class Image<br/>{<br/>public:<br/> int Redraw() const;<br/> //..<br/>private:<br/> mutable bool isLoaded;//can be changed by a const function<br/>}; </p>
<p>不像普通的数据成员，const 成员函数可以修改 mutable 数据成员。</p>
<p>Mutable 数据成员的使用看上去像是骗术，因为它能够使 const 函数修改对象的数据成员。然而，明智地使用 mutable 关键字可以提高代码质量，因为它能够让你向用户隐藏实现细节，而无须使用不确定的东西，比如 const_cast&lt;&gt;。</p>
<p></span></p>
<h5>对象的状态</h5>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"/>
<p>一个对象的状态由其非静态数据成员的值构成，因此，修改一个数据成员将会改变整个对象的状态。将一个成员函数声明为 const 能够保证它不会改变对象的状态。</p>
<p>然而在一些情况下，对象的逻辑状态与基物理状态之间可能有差别。例如，对于一个表示绘画图像的对象就存在这种情况。如果图像还没有更改，那么我们就认为其状态没有发生变化。然而，从底层实现方面来说，如果大对象在一段时间没有活动，那么它们的内存通常会被交换到一个文件中。交换一个图像并不会真地影响其状态，但是对象的一些数据成员可能会发生变化，在这里可能会发生变化的是指针、标志位等。</p>
<p>在用户调用一个诸如 Redraw() 之类的 const 成员函数时，他们并不关心这个函数在内部是如何实现的。从他们的角度来说，这个函数并不改变对象的逻辑状态，因此被声明为 const。Redraw() 有可能修改对象的物理状态这一事实是一个他们不应该关心的实现细节。例如：</p>
<p>int Image::Redraw() const<br/>{<br/> if (isLoaded==false)<br/> {<br/>  //..read image data from a disk into a local buffer<br/>  isLoaded=true; //changing a data member&#8217;s value<br/> }<br/>  //..paint image in the screen<br/>} </p>
<p>class Image<br/></p>
<h5>可变（mutable）数据成员</h5>
<p>如果尝试编译这段代码，你会得到一个编译错误。虽然 Redraw() 声明为 const，但是它修改了一个数据成员。解决这个编译错误的方法是将 isLoaded 声明为一个 mutable 数据成员：</p>
<p>class Image<br/>{<br/>public:<br/> int Redraw() const;<br/> //..<br/>private:<br/> mutable bool isLoaded;//can be changed by a const function<br/>}; </p>
<p>不像普通的数据成员，const 成员函数可以修改 mutable 数据成员。</p>
<p>Mutable 数据成员的使用看上去像是骗术，因为它能够使 const 函数修改对象的数据成员。然而，明智地使用 mutable 关键字可以提高代码质量，因为它能够让你向用户隐藏实现细节，而无须使用不确定的东西，比如 const_cast&lt;&gt;。</p>
<p>volatile关键字</p>
<p>　　volatile是c/c++中一个鲜为人知的关键字,该关键字告诉编译器不要持有变量的临时拷贝,它可以适用于基础类型<br/>　　如：int,char,long&#8230;&#8230;也适用于C的结构和C++的类。当对结构或者类对象使用volatile修饰的时候，结构或者<br/>　　类的所有成员都会被视为volatile.</p>
<p>　　使用volatile并不会否定对CRITICAL_SECTION,Mutex,Event等同步对象的需要<br/>　　例如：<br/>　　int i;<br/>　　i = i + 3;<br/>　　无论如何，总是会有一小段时间，i会被放在一个寄存器中，因为算术运算只能在寄存器中进行。一般来说，volatitle<br/>　　关键字适用于行与行之间，而不是放在行内。</p>
<p>　　我们先来实现一个简单的函数，来观察一下由编译器产生出来的汇编代码中的不足之处，并观察volatile关键字如何修正<br/>　　这个不足之处。在这个函数体内存在一个busy loop(所谓busy loop也叫做busy waits,是一种高度浪费CPU时间的循环方法)</p>
<p>
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　oid getKey(char* pch)<br/>　　{<br/>　　while (*pch == 0)<br/>　　;<br/>　　}</td>
</tr>
</tbody>
</table>
<p>　　当你在VC开发环境中将最优化选项都关闭之后，编译这个程序，将获得以下结果(汇编代码)<br/><br/><br />
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　　;       while (*pch == 0)<br/>　　$L27<br/>　　; Load the address stored in pch<br/>　　mov eax, DWORD PTR _pch$[ebp]<br/>　　; Load the character into the EAX register<br/>　　movsx eax, BYTE PTR [eax]<br/>　　; Compare the value to zero<br/>　　test eax, eax<br/>　　; If not zero, exit loop<br/>　　jne $L28<br/>　　;<br/>　　jmp $L27<br/>　　$L28<br/>　　;}</td>
</tr>
</tbody>
</table>
<p>　　这段没有优化的代码不断的载入适当的地址，载入地址中的内容，测试结果。效率相当的低，但是结果非常准确</p>
<p>　　现在我们再来看看将编译器的所有最优化选项开关都打开以后，重新编译程序，生成的汇编代码，和上面的代码<br/><br/>　　比较一下有什么不同<br/><br/><br />
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　　;{ <br/>　　; Load the address stored in pch<br/>　　mov eax, DWORD PTR _pch$[esp-4]<br/>　　; Load the character into the AL register<br/>　　movsx al, BYTE PTR [eax]<br/>　　; while (*pch == 0)<br/>　　; Compare the value in the AL register to zero<br/>　　test al, al<br/>　　; If still zero, try again<br/>　　je SHORT $L84<br/>　　;<br/>　　;}</td>
</tr>
</tbody>
</table>
<p><br/><br clear="all"/></p>
<p></span></font></span></font></p>
<p><font color="#000000"><span class="h2"><strong>使用可变（mutable）成员隐藏实现细节</strong></span> <br/><br/></font><span class="hui"><font color="#000000">作者： </font><font color="#0000ff">Builder.com</font></span></p>
<p/>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"><font face="Times New Roman" color="#000000"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><span class="hui">键字 mutable 是一个奇怪的修饰符（specifier），它只能够用于一个类的非静态数据成员。下面我将讨论 mutable 的语义和用法，但是首先我要解释一下 C++ 对象模型的一个关键概念。</span></p>
<p></span></font></p>
<p><span class="hui">键字 mutable 是一个奇怪的修饰符（specifier），它只能够用于一个类的非静态数据成员。下面我将讨论 mutable 的语义和用法，但是首先我要解释一下 C++ 对象模型的一个关键概念。</span></p>
<p/><font face="Times New Roman" color="#000000"><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: navy; mso-bidi-font-size: 12.0pt">
<p><span class="hui"><br />
<h5>对象的状态</h5>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"/>
<p>一个对象的状态由其非静态数据成员的值构成，因此，修改一个数据成员将会改变整个对象的状态。将一个成员函数声明为 const 能够保证它不会改变对象的状态。</p>
<p>然而在一些情况下，对象的逻辑状态与基物理状态之间可能有差别。例如，对于一个表示绘画图像的对象就存在这种情况。如果图像还没有更改，那么我们就认为其状态没有发生变化。然而，从底层实现方面来说，如果大对象在一段时间没有活动，那么它们的内存通常会被交换到一个文件中。交换一个图像并不会真地影响其状态，但是对象的一些数据成员可能会发生变化，在这里可能会发生变化的是指针、标志位等。</p>
<p>在用户调用一个诸如 Redraw() 之类的 const 成员函数时，他们并不关心这个函数在内部是如何实现的。从他们的角度来说，这个函数并不改变对象的逻辑状态，因此被声明为 const。Redraw() 有可能修改对象的物理状态这一事实是一个他们不应该关心的实现细节。例如：</p>
<p>int Image::Redraw() const<br/>{<br/> if (isLoaded==false)<br/> {<br/>  //..read image data from a disk into a local buffer<br/>  isLoaded=true; //changing a data member&#8217;s value<br/> }<br/>  //..paint image in the screen<br/>} </p>
<p>class Image<br/></p>
<h5>可变（mutable）数据成员</h5>
<p>如果尝试编译这段代码，你会得到一个编译错误。虽然 Redraw() 声明为 const，但是它修改了一个数据成员。解决这个编译错误的方法是将 isLoaded 声明为一个 mutable 数据成员：</p>
<p>class Image<br/>{<br/>public:<br/> int Redraw() const;<br/> //..<br/>private:<br/> mutable bool isLoaded;//can be changed by a const function<br/>}; </p>
<p>不像普通的数据成员，const 成员函数可以修改 mutable 数据成员。</p>
<p>Mutable 数据成员的使用看上去像是骗术，因为它能够使 const 函数修改对象的数据成员。然而，明智地使用 mutable 关键字可以提高代码质量，因为它能够让你向用户隐藏实现细节，而无须使用不确定的东西，比如 const_cast&lt;&gt;。</p>
<p></span></p>
<h5>对象的状态</h5>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 180%"/>
<p>一个对象的状态由其非静态数据成员的值构成，因此，修改一个数据成员将会改变整个对象的状态。将一个成员函数声明为 const 能够保证它不会改变对象的状态。</p>
<p>然而在一些情况下，对象的逻辑状态与基物理状态之间可能有差别。例如，对于一个表示绘画图像的对象就存在这种情况。如果图像还没有更改，那么我们就认为其状态没有发生变化。然而，从底层实现方面来说，如果大对象在一段时间没有活动，那么它们的内存通常会被交换到一个文件中。交换一个图像并不会真地影响其状态，但是对象的一些数据成员可能会发生变化，在这里可能会发生变化的是指针、标志位等。</p>
<p>在用户调用一个诸如 Redraw() 之类的 const 成员函数时，他们并不关心这个函数在内部是如何实现的。从他们的角度来说，这个函数并不改变对象的逻辑状态，因此被声明为 const。Redraw() 有可能修改对象的物理状态这一事实是一个他们不应该关心的实现细节。例如：</p>
<p>int Image::Redraw() const<br/>{<br/> if (isLoaded==false)<br/> {<br/>  //..read image data from a disk into a local buffer<br/>  isLoaded=true; //changing a data member&#8217;s value<br/> }<br/>  //..paint image in the screen<br/>} </p>
<p>class Image<br/></p>
<h5>可变（mutable）数据成员</h5>
<p>如果尝试编译这段代码，你会得到一个编译错误。虽然 Redraw() 声明为 const，但是它修改了一个数据成员。解决这个编译错误的方法是将 isLoaded 声明为一个 mutable 数据成员：</p>
<p>class Image<br/>{<br/>public:<br/> int Redraw() const;<br/> //..<br/>private:<br/> mutable bool isLoaded;//can be changed by a const function<br/>}; </p>
<p>不像普通的数据成员，const 成员函数可以修改 mutable 数据成员。</p>
<p>Mutable 数据成员的使用看上去像是骗术，因为它能够使 const 函数修改对象的数据成员。然而，明智地使用 mutable 关键字可以提高代码质量，因为它能够让你向用户隐藏实现细节，而无须使用不确定的东西，比如 const_cast&lt;&gt;。</p>
<p>volatile关键字</p>
<p>　　volatile是c/c++中一个鲜为人知的关键字,该关键字告诉编译器不要持有变量的临时拷贝,它可以适用于基础类型<br/>　　如：int,char,long&#8230;&#8230;也适用于C的结构和C++的类。当对结构或者类对象使用volatile修饰的时候，结构或者<br/>　　类的所有成员都会被视为volatile.</p>
<p>　　使用volatile并不会否定对CRITICAL_SECTION,Mutex,Event等同步对象的需要<br/>　　例如：<br/>　　int i;<br/>　　i = i + 3;<br/>　　无论如何，总是会有一小段时间，i会被放在一个寄存器中，因为算术运算只能在寄存器中进行。一般来说，volatitle<br/>　　关键字适用于行与行之间，而不是放在行内。</p>
<p>　　我们先来实现一个简单的函数，来观察一下由编译器产生出来的汇编代码中的不足之处，并观察volatile关键字如何修正<br/>　　这个不足之处。在这个函数体内存在一个busy loop(所谓busy loop也叫做busy waits,是一种高度浪费CPU时间的循环方法)</p>
<p>
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　oid getKey(char* pch)<br/>　　{<br/>　　while (*pch == 0)<br/>　　;<br/>　　}</td>
</tr>
</tbody>
</table>
<p>　　当你在VC开发环境中将最优化选项都关闭之后，编译这个程序，将获得以下结果(汇编代码)<br/><br/><br />
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　　;       while (*pch == 0)<br/>　　$L27<br/>　　; Load the address stored in pch<br/>　　mov eax, DWORD PTR _pch$[ebp]<br/>　　; Load the character into the EAX register<br/>　　movsx eax, BYTE PTR [eax]<br/>　　; Compare the value to zero<br/>　　test eax, eax<br/>　　; If not zero, exit loop<br/>　　jne $L28<br/>　　;<br/>　　jmp $L27<br/>　　$L28<br/>　　;}</td>
</tr>
</tbody>
</table>
<p>　　这段没有优化的代码不断的载入适当的地址，载入地址中的内容，测试结果。效率相当的低，但是结果非常准确</p>
<p>　　现在我们再来看看将编译器的所有最优化选项开关都打开以后，重新编译程序，生成的汇编代码，和上面的代码<br/><br/>　　比较一下有什么不同<br/><br/><br />
<table bordercolor="#55aaff" cellspacing="0" cellpadding="0" rules="none" width="500" align="center" bgcolor="#ddedfb" border="1">
<tbody>
<tr>
<td width="10"><br/></td>
<td>　　;{ <br/>　　; Load the address stored in pch<br/>　　mov eax, DWORD PTR _pch$[esp-4]<br/>　　; Load the character into the AL register<br/>　　movsx al, BYTE PTR [eax]<br/>　　; while (*pch == 0)<br/>　　; Compare the value in the AL register to zero<br/>　　test al, al<br/>　　; If still zero, try again<br/>　　je SHORT $L84<br/>　　;<br/>　　;}</td>
</tr>
</tbody>
</table>
<p><br/><br clear="all"/></p>
<p></span></font></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2004/12/17/205506.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C\c++基础知识，面试常见问题</title>
		<link>http://blog.donews.com/skyfei/archive/2004/12/02/191169.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2004/12/02/191169.aspx#comments</comments>
		<pubDate>Thu, 02 Dec 2004 09:23:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[c/c++ 技术文章网络收藏]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2004/12/02/191169.aspx</guid>
		<description><![CDATA[C\c++基础知识，面试常见问题]]></description>
			<content:encoded><![CDATA[<p><P><STRONG>链表与数组的区别<BR></STRONG>A 从逻辑结构来看<BR>A-1. 数组必须事先定义固定的长度（元素个数），不能适应数据动态地增减的情况。当&nbsp;&nbsp;&nbsp;&nbsp; 数据增加时，可能超出原先定义的元素个数；当数据减少时，造成内存浪费。</P><br />
<P>A-2. 链表动态地进行存储分配，可以适应数据动态地增减的情况，且可以方便地插入、&nbsp;&nbsp;&nbsp;&nbsp; 删除数据项。（数组中插入、删除数据项时，需要移动其它数据项）</P><br />
<P><BR>B 从内存存储来看<BR>B-1. (静态)数组从栈中分配空间, 对于程序员方便快速,但是自由度小<BR>B-2. 链表从堆中分配空间, 自由度大但是申请管理比较麻烦.<BR><BR></P><br />
<P class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt 147pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan; mso-outline-level: 3" align=left><B><SPAN style="FONT-SIZE: 13.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">堆和栈的区别</SPAN></B><B><SPAN lang=EN-US style="FONT-SIZE: 13.5pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></B></P><br />
<P class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">solost </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> 2004</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">年</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> 10</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">月</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">09</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">日</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">发表</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan" align=left><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">一、预备知识</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">&#8212;</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">程序的内存分配</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN></B><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">一个由</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">c/C++</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">编译的程序占用的内存分为以下几个部分</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">1</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">、<B style="mso-bidi-font-weight: normal">栈区（</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">stack</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">）</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">&#8212;&nbsp; &nbsp;</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">由<B style="mso-bidi-font-weight: normal">编译器</B></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">(Compiler)</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">自动分配释放</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">，存放<B style="mso-bidi-font-weight: normal">函数的参数值</B>，<B style="mso-bidi-font-weight: normal">局部变量</B>的值等。其操作方式类似于数据结构中的栈。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">2</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">、<B style="mso-bidi-font-weight: normal">堆区（</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">heap</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">）</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> &#8212;&nbsp; &nbsp;</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">一般由<B style="mso-bidi-font-weight: normal">程序员</B>分配释放，</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">若程序员不释放，程序结束时可能由</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">OS</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">回收</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">。注意它与数据结构中的堆是两回事，分配方式倒是类似于链表，呵呵。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">3</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">、<B style="mso-bidi-font-weight: normal">全局区（静态区）</B>（</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">static</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">）</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">&#8212;</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">，<B style="mso-bidi-font-weight: normal">全局变量和静态变量的</B>存储是放在一块的，<B style="mso-bidi-font-weight: normal">初始化</B>的全局变量和静态变量在一块区域，</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> </SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">未初始化</SPAN></B><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">的全局变量和未初始化的静态变量在相邻的另一块区域。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> &#8211; </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">程序结束后有系统释放</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> </SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">4</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">、<B style="mso-bidi-font-weight: normal">文字常量区</B></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">&nbsp;&nbsp;&#8212; </SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">常量字符串</SPAN></B><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">就是放在这里的。</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt"> </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">程序结束后由<B style="mso-bidi-font-weight: normal">系统释放</B></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">5</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">、<B style="mso-bidi-font-weight: normal">程序代码区</B></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">&#8212; </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt">存放<B style="mso-bidi-font-weight: normal">函数体的二进制代码</B>。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR style="mso-special-character: line-break"><BR style="mso-special-character: line-break"><o:p></o:p></SPAN></P><br />
<P class=MsoNormal style="BACKGROUND: white; MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">二、例子程序</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">这是一个前辈写的，非常详细</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>//main.cpp <BR>int a = 0; </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">全局初始化区</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>char *p1; </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">全局未初始化区</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>main() <BR>{ <BR>int b; </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">栈</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>char s[] = &#8220;abc&#8221;; </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">栈</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>char *p2; </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">栈</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>char *p3 = &#8220;123456&#8243;; 123456\0</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">在常量区，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">p3</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">在栈上。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>static int c =0</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">；</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">全局（静态）初始化区</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>p1 = (char *)malloc(10); <BR>p2 = (char *)malloc(20); <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">分配得来得</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">10</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">和</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">20</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">字节的区域就在堆区。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>strcpy(p1, &#8220;123456&#8243;); 123456\0</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">放在常量区，编译器<B style="mso-bidi-font-weight: normal">可能</B>会将它与</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">p3</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">所指向的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">&#8220;123456&#8243;</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">优化成一个地方。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>} <BR><BR><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">二、堆和栈的理论知识</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR><B style="mso-bidi-font-weight: normal">2.1</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">申请方式</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">stack: <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">由系统自动分配。</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">例如，声明在函数中一个局部变量</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> int b; </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">系统自动在栈中为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">b</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">开辟空间</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>heap: <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">需要程序员自己申请，并指明大小，在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">c</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">中</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">malloc</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">函数</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">如</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">p1 = (char *)malloc(10); <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">C++</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">中用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">new</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">运算符</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">如</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">p2 = (char *)malloc(10); <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">但是注意</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">p1</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">、</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">p2</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">本身是在栈中的。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR><BR><BR><B style="mso-bidi-font-weight: normal">2.2 </B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">申请后系统的响应</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">栈：只要栈的剩余空间大于所申请空间，系统将为程序提供内存，否则将报异常提示栈溢出。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">堆：首先应该知道操作系统有一个记录空闲内存地址的链表，当系统收到程序的申请时，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">会遍历该链表，寻找第一个空间大于所申请空间的堆结点，然后将该结点从空闲结点链表中删除，并将该结点的空间分配给程序，另外，对于大多数系统，会在这块内存空间中的首地址处记录本次分配的大小，这样，代码中的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">delete</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">语句才能正确的释放本内存空间。另外，由于找到的堆结点的大小不一定正好等于申请的大小，系统会自动的将多余的那部分重新放入空闲链表中。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR><BR><B style="mso-bidi-font-weight: normal">2.3</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">申请大小的限制</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">栈：在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">Windows</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">下</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">, </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">栈是<B style="mso-bidi-font-weight: normal">向低地址扩展</B>的数据结构，是一块<B style="mso-bidi-font-weight: normal">连续</B>的内存的区域。这句话的意思是栈顶的地址和栈的最大容量是<B style="mso-bidi-font-weight: normal">系统预先规定好</B>的，在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">WINDOWS</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">下，栈的大小是</SPAN><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">2M</SPAN></B><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">（也有的说是</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">1M</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">，总之是一个编译时就确定的常数），如果申请的空间超过栈的剩余空间时，将提示</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">overflow</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">。因此，能从栈获得的空间较小。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">堆：堆是<B style="mso-bidi-font-weight: normal">向高地址扩展</B>的数据结构，是<B style="mso-bidi-font-weight: normal">不连续</B>的内存区域。这是由于系统是用链表来存储的空闲内存地址的，自然是不连续的，而链表的遍历方向是由低地址向高地址。堆的大小受限于计算机系统中<B style="mso-bidi-font-weight: normal">有效的虚拟内存</B>。由此可见，堆获得的空间比较灵活，也比较大。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR><BR><BR><B style="mso-bidi-font-weight: normal">2.4</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">申请效率的比较：</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">栈由系统自动分配，速度较快。但程序员是<B style="mso-bidi-font-weight: normal">无法控制</B>的。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">堆是由</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">new</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">分配的内存，一般速度比较慢，而且<B style="mso-bidi-font-weight: normal">容易产生内存碎片</B></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">,</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">不过用起来最<B style="mso-bidi-font-weight: normal">方便</B></SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">. <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">另外，在</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">WINDOWS</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">下，最好的方式是用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">VirtualAlloc</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">分配内存，他不是在堆，也不是在栈是直接在进程的地址空间中保留一快内存，虽然用起来最不方便。但是速度快，也最灵活。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR><BR><B style="mso-bidi-font-weight: normal">2.5</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">堆和栈中的存储内容</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">栈：</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">在函数调用时，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">(1) </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">第一个进栈的是主函数中后的下一条指令（函数调用语句的下一条可执行语句）的<B style="mso-bidi-font-weight: normal">地址</B>，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">(2) </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">然后是函数的各个参数，在大多数的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">C</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">编译器中，<B style="mso-bidi-font-weight: normal">参数是由右往左入栈</B>的，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">(3) </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">然后是函数中的局部变量。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><SPAN style="mso-tab-count: 1"> </SPAN></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">注意</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">: </SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">静态变量是不入栈的。</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">当本次函数调用结束后，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">(1) </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">局部变量先出栈，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">(2) </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">然后是参数，</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">(3) </SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">最后栈顶指针指向最开始存的地址，也就是主函数中的下一条指令，<B style="mso-bidi-font-weight: normal">程序由该点继续运行</B>。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">堆：一般是在堆的头部用一个字节存放堆的大小。<B style="mso-bidi-font-weight: normal">堆中的具体内容有程序员安排。</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR><BR><B style="mso-bidi-font-weight: normal">2.6</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">存取效率的比较</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR>char s1[] = &#8220;aaaaaaaaaaaaaaa&#8221;; <BR>char *s2 = &#8220;bbbbbbbbbbbbbbbbb&#8221;; <BR>aaaaaaaaaaa</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">是在<B style="mso-bidi-font-weight: normal">运行时刻</B>赋值的；</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">而</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">bbbbbbbbbbb</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">是在<B style="mso-bidi-font-weight: normal">编译时</B>就确定的；</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">但是，在以后的存取中，在栈上的数组比指针所指向的字符串</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">(</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">例如堆</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">)</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">快。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">比如：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>#include <BR>void main() <BR>{ <BR>char a = 1; <BR>char c[] = &#8220;1234567890&#8243;; <BR>char *p =&#8221;1234567890&#8243;; <BR>a = c[1]; <BR>a = p[1]; <BR>return; <BR>} <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">对应的汇编代码</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR>10: a = c[1]; <BR>00401067 8A 4D F1 mov cl,byte ptr [ebp-0Fh] <BR>0040106A 88 4D FC mov byte ptr [ebp-4],cl <BR>11: a = p[1]; <BR>0040106D 8B 55 EC mov edx,dword ptr [ebp-14h] <BR>00401070 8A 42 01 mov al,byte ptr [edx+1] <BR>00401073 88 45 FC mov byte ptr [ebp-4],al <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">第一种在读取时直接就把字符串中的元素读到寄存器</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">cl</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">中，而第二种则要先把指针值读到</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">edx</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">中，在根据</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">edx</SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">读取字符，显然慢了。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR><BR><BR><B style="mso-bidi-font-weight: normal">2.7</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">小结：</SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">堆和栈的区别可以用如下的比喻来看出：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> <BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">使用栈就象我们去饭馆里吃饭，只管点菜（发出申请）、付钱、和吃（使用），吃饱了就走，不必理会切菜、洗菜等准备工作和洗碗、刷锅等扫尾工作，他的好处是<B style="mso-bidi-font-weight: normal">快捷，但是自由度小。</B></SPAN><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"> </SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><BR></SPAN><SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">使用堆就象是自己动手做喜欢吃的菜肴，比较麻烦，但是比较符合自己的口味，而且自由度大。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P><br />
<P><BR><STRONG>深度优先搜索与广度优先搜索算法有何区别呢？<BR></STRONG>　　通常深度优先搜索法不全部保留结点，扩展完的结点从数据库中弹出删去，这样，一般在数据库中存储的结点数就是深度值，因此它占用空间较少。所以，当搜索树的结点较多，用其它方法易产生内存溢出时，深度优先搜索不失为一种有效的求解方法。<BR>　　广度优先搜索算法，一般需存储产生的所有结点，占用的存储空间要比深度优先搜索大得多，因此，程序设计中，必须考虑溢出和节省内存空间的问题。但广度优先搜索法一般无回溯操作，即入栈和出栈的操作，所以运行速度比深度优先搜索要快些<BR></P></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2004/12/02/191169.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>重启IIS和SqlServer的命令行</title>
		<link>http://blog.donews.com/skyfei/archive/2004/11/30/188905.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2004/11/30/188905.aspx#comments</comments>
		<pubDate>Tue, 30 Nov 2004 09:40:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2004/11/30/188905.aspx</guid>
		<description><![CDATA[摘自http://www.cnblogs.com/roky/net stop iisadmin /ynet start w3svc
net stop mssqlservernet start mssqlserverIISRESET.EXE (C) Microsoft Corp. 1998-1999 用法: iisreset [computername] /RESTART 停止然后重新启动所有 Internet 服务。 /START 启动所有 Internet 服务。 /STOP 停止所有 Internet 服务。 /REBOOT 重新启动计算机。 /REBOOTONERROR 如果在启动、停止或重新启动 Internet 服务时出错，则重新启 动计算机。 /NOFORCE 如果试图正常停止服务失败，不强制终止 Internet 服务。 /TIMEOUT:val 指定等待 Internet 服务的成功停止的超时值(以秒为单位)。 如果已指定 REBOOTONERROR 参数，超时后可以重新启动计算机。 服务重新启动的默认值为 20 秒，停止为 60 秒，计算机重新启 动为 0 秒。 [...]]]></description>
			<content:encoded><![CDATA[<p>摘自<A href="http://www.cnblogs.com/roky/">http://www.cnblogs.com/roky/</A><BR><BR>net stop iisadmin /y<BR>net start w3svc<br />
<P>net stop mssqlserver<BR>net start mssqlserver<BR><BR>IISRESET.EXE (C) Microsoft Corp. 1998-1999 <BR><BR>用法: <BR>iisreset [computername] <BR><BR>/RESTART 停止然后重新启动所有 Internet 服务。 <BR>/START 启动所有 Internet 服务。 <BR>/STOP 停止所有 Internet 服务。 <BR>/REBOOT 重新启动计算机。 <BR>/REBOOTONERROR 如果在启动、停止或重新启动 Internet 服务时出错，则重新启 <BR>动计算机。 <BR>/NOFORCE 如果试图正常停止服务失败，不强制终止 Internet 服务。 <BR>/TIMEOUT:val 指定等待 Internet 服务的成功停止的超时值(以秒为单位)。 <BR>如果已指定 REBOOTONERROR 参数，超时后可以重新启动计算机。 <BR>服务重新启动的默认值为 20 秒，停止为 60 秒，计算机重新启 <BR>动为 0 秒。 <BR>/STATUS 显示所有 Internet 服务的状态。 <BR>/ENABLE 启用本地系统上 Internet 服务的重新启动。 <BR>/DISABLE 禁用本地系统上 Internet 服务的重新启动。 </P></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2004/11/30/188905.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++:memset ,memcpy 和strcpy 的根本区别？</title>
		<link>http://blog.donews.com/skyfei/archive/2004/11/20/176430.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2004/11/20/176430.aspx#comments</comments>
		<pubDate>Sat, 20 Nov 2004 04:02:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[c/c++ 技术文章网络收藏]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2004/11/20/176430.aspx</guid>
		<description><![CDATA[新增：ASSERT()是干什么用的 引自：http://www.china-askpro.com/msg34/qa79.shtml]]></description>
			<content:encoded><![CDATA[<p>#include &#8220;memory.h&#8221;<BR><BR>memset用来对一段内存空间全部设置为某个字符，一般用在对定义的字符串进行初始化为&#8216; &#8217;或&#8216;\0&#8217;；例:char a[100];memset(a, &#8216;\0&#8242;, sizeof(a));<br />
<P>memcpy用来做内存拷贝，你可以拿它拷贝任何数据类型的对象，可以指定拷贝的数据长度；例：char a[100],b[50]; memcpy(b, a, sizeof(b));注意如用sizeof(a)，会造成b的内存地址溢出。<br />
<P>strcpy就只能拷贝字符串了，它遇到&#8217;\0&#8242;就结束拷贝；例：char a[100],b[50];strcpy(a,b);如用strcpy(b,a)，要注意a中的字符串长度（第一个&#8216;\0&#8217;之前）是否超过50位，如超过，则会造成b的内存地址溢出。<BR><BR>strcpy <BR>&nbsp;原型：extern char *strcpy(char *dest,char *src); <BR>&nbsp;用法：#include &lt;string.h&gt;<BR>&nbsp;功能：把src所指由NULL结束的字符串复制到dest所指的数组中。<BR>&nbsp;说明：src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。<BR>&nbsp; &nbsp; &nbsp; &nbsp;返回指向dest的指针。<BR>memcpy <BR>&nbsp;原型：extern void *memcpy(void *dest, void *src, unsigned int count);<BR>&nbsp;用法：#include &lt;string.h&gt;<BR>&nbsp;功能：由src所指内存区域复制count个字节到dest所指内存区域。<BR>&nbsp;说明：src和dest所指内存区域不能重叠，函数返回指向dest的指针。<BR>memset<BR>&nbsp;原型：extern void *memset(void *buffer, int c, int count);<BR>&nbsp;用法：#include &lt;string.h&gt;<BR>&nbsp;功能：把buffer所指内存区域的前count个字节设置成字符c。<BR>&nbsp;说明：返回指向buffer的指针。<BR><BR><BR><STRONG>ASSERT()是干什么用的<BR><BR></STRONG>&nbsp;&nbsp;ASSERT()是一个调试程序时经常使用的宏，在程序运行时它计算括号内的表达式，如果表达式为FALSE (0), 程序将报告错误，并终止执行。如果表达式不为0，则继续执行后面的语句。这个宏通常原来判断程序中是否出现了明显非法的数据，如果出现了终止程序以免导致严重后果，同时也便于查找错误。例如，变量n在程序中不应该为0，如果为0可能导致错误，你可以这样写程序： <BR>&nbsp;&nbsp;&nbsp;&nbsp;&#8230;&#8230; <BR>&nbsp;&nbsp;&nbsp;&nbsp;ASSERT( n != 0); <BR>&nbsp;&nbsp;&nbsp;&nbsp;k = 10/ n; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&#8230;&#8230; <BR>&nbsp;&nbsp;&nbsp;&nbsp;ASSERT只有在Debug版本中才有效，如果编译为Release版本则被忽略。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;assert()的功能类似，它是ANSI C标准中规定的函数，它与ASSERT的一个重要区别是可以用在Release版本中。 <BR><BR><BR>system（&#8221;pause&#8221;);<BR>系统的暂停程序，按任意键继续，屏幕会打印，&#8220;按任意键继续。。。。。&#8221; 省去了使用getchar（）；</P></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2004/11/20/176430.aspx/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASSERT()是干什么用的？</title>
		<link>http://blog.donews.com/skyfei/archive/2004/11/18/174213.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2004/11/18/174213.aspx#comments</comments>
		<pubDate>Thu, 18 Nov 2004 02:46:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[c/c++ 技术文章网络收藏]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2004/11/18/174213.aspx</guid>
		<description><![CDATA[assert是为了处理程序中很难扑捉到的错误。其作用是在程序发生错误的时候使程序终止执行。 assert是C++语言预先定义好的，使用断言时必须假头文件&#60;cassert&#62; 事实上assert不紧可以终止程序，还可以提示更加详细的提示信息。一般提示用户那个文件的那行出了问题。 由于assert是在某种错误的情况下终止正在执行的程序，并指出错误的信息。所以_ 在某种意义上assert等同于return 原则上assert对于程序开发阶段很有用，但在程序开发结束，已经投入使用后，应该取消代码中的所有_ 断言，但在大型软件开发结束后很难做到把断言全部去掉，所以采用一种方式让断言语句尽管存在， 可是不起作用，方法是在#include&#60;assert&#62;语句前加#define NDEBUG assert(expression);函数很简单，如果expression是TURE或者1，则不产生任何反映 如果expression是FALSE或者0，则跳出正在执行的模块，并提示错误信息。 ASSERT()是一个调试程序时经常使用的宏，在程序运行时它计算括号内的表达式，如果表达式为FALSE (0), 程序将报告错误，并终止执行。如果表达式不为0，则继续执行后面的语句。这个宏通常原来判断程序中是否出现了明显非法的数据，如果出现了终止程序以免导致严重后果，同时也便于查找错误。例如，变量n在程序中不应该为0，如果为0可能导致错误，你可以这样写程序： &#160;&#160;&#160;&#160;&#8230;&#8230; &#160;&#160;&#160;&#160;ASSERT( n != 0); &#160;&#160;&#160;&#160;k = 10/ n; &#160;&#160;&#160;&#160;&#8230;&#8230; &#160;&#160;&#160;&#160;ASSERT只有在Debug版本中才有效，如果编译为Release版本则被忽略。 &#160;&#160;&#160;&#160;assert()的功能类似，它是ANSI C标准中规定的函数，它与ASSERT的一个重要区别是可以用在Release版本中。
&#160;&#160;&#160;&#160;
此问题由李海回答。 
]]></description>
			<content:encoded><![CDATA[<p><SPAN class=postbody><FONT size=2>assert是为了处理程序中很难扑捉到的错误。其作用是在程序发生错误的时候使程序终止执行。 <BR>assert是C++语言预先定义好的，使用断言时必须假头文件&lt;cassert&gt; <BR>事实上assert不紧可以终止程序，还可以提示更加详细的提示信息。一般提示用户那个文件的那行出了问题。 <BR>由于assert是在某种错误的情况下终止正在执行的程序，并指出错误的信息。所以_ <BR>在某种意义上assert等同于return <BR>原则上assert对于程序开发阶段很有用，但在程序开发结束，已经投入使用后，应该取消代码中的所有_ <BR>断言，但在大型软件开发结束后很难做到把断言全部去掉，所以采用一种方式让断言语句尽管存在， <BR>可是不起作用，方法是在#include&lt;assert&gt;语句前加#define NDEBUG <BR>assert(expression);函数很简单，如果expression是TURE或者1，则不产生任何反映 <BR>如果expression是FALSE或者0，则跳出正在执行的模块，并提示错误信息。 </FONT><BR><BR>ASSERT()是一个调试程序时经常使用的宏，在程序运行时它计算括号内的表达式，如果表达式为FALSE (0), 程序将报告错误，并终止执行。如果表达式不为0，则继续执行后面的语句。这个宏通常原来判断程序中是否出现了明显非法的数据，如果出现了终止程序以免导致严重后果，同时也便于查找错误。例如，变量n在程序中不应该为0，如果为0可能导致错误，你可以这样写程序： <BR>&nbsp;&nbsp;&nbsp;&nbsp;&#8230;&#8230; <BR>&nbsp;&nbsp;&nbsp;&nbsp;ASSERT( n != 0); <BR>&nbsp;&nbsp;&nbsp;&nbsp;k = 10/ n; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&#8230;&#8230; <BR>&nbsp;&nbsp;&nbsp;&nbsp;ASSERT只有在Debug版本中才有效，如果编译为Release版本则被忽略。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;assert()的功能类似，它是ANSI C标准中规定的函数，它与ASSERT的一个重要区别是可以用在Release版本中。<br />
<P><FONT size=-1>&nbsp;&nbsp;&nbsp;&nbsp;</FONT><br />
<P><FONT size=-1><I>此问题由<B>李海</B>回答。</I> </P></FONT></SPAN></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2004/11/18/174213.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>转载网文：毕业五年有感</title>
		<link>http://blog.donews.com/skyfei/archive/2004/11/13/168797.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2004/11/13/168797.aspx#comments</comments>
		<pubDate>Sat, 13 Nov 2004 11:49:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2004/11/13/168797.aspx</guid>
		<description><![CDATA[


发信人: Capa (卡帕 &#8212; 天道酬勤), 信区: Job 标 题: 毕业五年有感,给年轻人的一点忠告 zz 发信站: 日月光华 (2004年10月15日01:46:36 星期五), 站内信件 发信人: richwinner (投资顾问), 信区: Career 标 题: 毕业五年有感,给年轻人的一点忠告! 发信站: BBS 水木清华站 (Wed Oct 13 11:11:40 2004) 1.合作。不要随便与人合作，与人合作要考虑好利与弊。如果有想法尽快去干， 一个人努力的干，卖命的干。干到差不了，有资本了，可以与人短期性的合作。与 人合作目标要明确。 2.努力。工作要努力，随随便便过日子过四五年也是过，稍微努力的过四五年 也是过，努力的过四五年也是过，何不努力好好的干。如果努力的过好毕业后的四 五年，这对我们以后的人生很有帮助。 3.吃苦耐劳。不要怕吃苦。在创业阶段，我们要的是名气，是经验，有时候在 保本的情况下可以以低价策略来和别人竞争。我们出卖的是点脑力活，力气活，年 轻人，睡一觉起来什么都恢复了。 4.目标。生活要有目标，不仅仅是事业（赚钱）的目标，其他方面也要有目标， 如爱情方面的目标，健康方面的目标。家庭方面的目标。各个目标都要重视。只赚 了钱，不算人生的成功。 5.虚心学习。多与比自己大的人（长辈）/ 成功人事。交流学习，要虚心听取 / 认真分析他们的意见和建议，一面自己以后走弯路。 6.了解社会。多了解社会。多实践。多分析某些社会现象的因果厉害关系。认 真分析身边发生某些事情。正视社会的阴暗面。分析社会上某些不良风气，不要清 高自傲。也不要随波逐流。某些时候半事情，也需要这方面的帮助。 7.自由。出来外面做事情，关键是自由，愉快，能学到知识。每走一步都要分 析，不要因某一小点利益限制了自己的自由。 8.计划。给自己定一个五年计划，十年规划。每季度做什么事情，每个月做什 么事情。甚至每天做什么事情，有个计划，有个目标比较好。不要每天混混恶恶。 [...]]]></description>
			<content:encoded><![CDATA[<p><TABLE cellSpacing=0 cellPadding=0 width=500 border=0><br />
<TBODY><br />
<TR><br />
<TD class=setgreen vAlign=top height=26><BR>发信人: Capa (卡帕 &#8212; 天道酬勤), 信区: Job <BR>标 题: 毕业五年有感,给年轻人的一点忠告 zz <BR>发信站: 日月光华 (2004年10月15日01:46:36 星期五), 站内信件 <BR><BR>发信人: richwinner (投资顾问), 信区: Career <BR>标 题: 毕业五年有感,给年轻人的一点忠告! <BR>发信站: BBS 水木清华站 (Wed Oct 13 11:11:40 2004) <BR><BR>1.合作。不要随便与人合作，与人合作要考虑好利与弊。如果有想法尽快去干， <BR>一个人努力的干，卖命的干。干到差不了，有资本了，可以与人短期性的合作。与 <BR>人合作目标要明确。 <BR><BR>2.努力。工作要努力，随随便便过日子过四五年也是过，稍微努力的过四五年 <BR>也是过，努力的过四五年也是过，何不努力好好的干。如果努力的过好毕业后的四 <BR>五年，这对我们以后的人生很有帮助。 <BR><BR>3.吃苦耐劳。不要怕吃苦。在创业阶段，我们要的是名气，是经验，有时候在 <BR>保本的情况下可以以低价策略来和别人竞争。我们出卖的是点脑力活，力气活，年 <BR>轻人，睡一觉起来什么都恢复了。 <BR><BR>4.目标。生活要有目标，不仅仅是事业（赚钱）的目标，其他方面也要有目标， <BR>如爱情方面的目标，健康方面的目标。家庭方面的目标。各个目标都要重视。只赚 <BR>了钱，不算人生的成功。 <BR><BR>5.虚心学习。多与比自己大的人（长辈）/ 成功人事。交流学习，要虚心听取 <BR>/ 认真分析他们的意见和建议，一面自己以后走弯路。 <BR><BR>6.了解社会。多了解社会。多实践。多分析某些社会现象的因果厉害关系。认 <BR>真分析身边发生某些事情。正视社会的阴暗面。分析社会上某些不良风气，不要清 <BR>高自傲。也不要随波逐流。某些时候半事情，也需要这方面的帮助。 <BR><BR>7.自由。出来外面做事情，关键是自由，愉快，能学到知识。每走一步都要分 <BR>析，不要因某一小点利益限制了自己的自由。 <BR><BR>8.计划。给自己定一个五年计划，十年规划。每季度做什么事情，每个月做什 <BR>么事情。甚至每天做什么事情，有个计划，有个目标比较好。不要每天混混恶恶。 <BR>几年后你会发现，几年来一直没有目标，什么也没有做成。 <BR><BR>9.胆量。你是工人的子弟，或是农民的儿子。难免思想狭隘。不要盲目。盲从。 <BR>也不要胆小怕事。 <BR><BR>多锻炼，大胆去做事情，只要不违法。大胆去做。即使失败了，也为下次积累 <BR>经验。&#8221; 商场如战场&#8221; ，这句话一点不假。想想，在战场上，不是你死就是我亡。 <BR><BR>10. 谋略。人生活在社会上，就是要用自己的智慧谋略和别人都智斗勇。即使 <BR>某些人的成功，不是电视小说里说的那么偶然的。有其必然性。生活中不玩点小技 <BR>巧（犯法的不做。害人的不做）。哪能那么容易就成功。 <BR><BR>11. 不要害怕贫穷。也许你家里没有几十万是百万。大胆的去做事情，不要怕 <BR>贫穷。即使我们事情做失败了，我们大不了回到起点。还是穷人。 <BR><BR>12. 学习。不断充实自己。学习新的知识。多学点技能。为以后作准备。也可 <BR>作为以后的娱乐消遣。如：驾驶技术，炒菜做饭，毛笔字等。 <BR><BR>13. 惜时。如果以上你都做了，我估计你的时间过得很快。我常听某某人说： <BR>&#8221; 这一辈子，就象昨天今天一样。&#8221; ，毛泽东说：&#8221; 天地转，光阴迫。一万年太久， <BR>只争朝夕。&#8221;.&#8221; 三是八年过去弹指一挥间。&#8221; ，不要因碌碌无为而悔恨！！！ <BR><BR>&#8211; <BR>爱从一个微笑开始， 在热吻中延伸，却随眼泪逝去&#8230; <BR>※ 来源:&#183;日月光华 bbs.fudan.edu.cn&#183;[FROM: 218.81.218.45] <BR>※ 修改:&#183;Capa 於 10月15日02:15:21 修改本文&#183;[FROM: 218.81.218.45] <BR>&#8211; <BR>※ 转寄:&#183;日月光华 bbs.fudan.edu.cn&#183;[FROM: 10.85.24.224]</TD></TR></TBODY></TABLE></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2004/11/13/168797.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>转载摘录:.net中类和结构的区别</title>
		<link>http://blog.donews.com/skyfei/archive/2004/11/10/166028.aspx</link>
		<comments>http://blog.donews.com/skyfei/archive/2004/11/10/166028.aspx#comments</comments>
		<pubDate>Wed, 10 Nov 2004 05:35:00 +0000</pubDate>
		<dc:creator>skyfei</dc:creator>
				<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://blog.donews.com/skyfei/archive/2004/11/10/166028.aspx</guid>
		<description><![CDATA[出处：PConline]]></description>
			<content:encoded><![CDATA[<p>二 .类与结构的差别<br />
<P>　　1.值类型与引用类型</P><br />
<P>　　结构是值类型：值类型在堆栈上分配地址，所有的基类型都是结构类型，例如：int 对应System.int32 结构，string 对应 system.string 结构 ，通过使用结构可以创建更多的值类型</P><br />
<P>　　类是引用类型：引用类型在堆上分配地址</P><br />
<P>　　堆栈的执行效率要比堆的执行效率高，可是堆栈的资源有限，不适合处理大的逻辑复杂的对象。所以结构处理作为基类型对待的小对象，而类处理某个商业逻辑</P><br />
<P>　　因为结构是值类型所以结构之间的赋值可以创建新的结构，而类是引用类型，类之间的赋值只是复制引用</P><br />
<P>　　注：</P><br />
<P>　　1.虽然结构与类的类型不一样，可是他们的基类型都是对象（object）,c#中所有类型的基类型都是object </P><br />
<P>　　2.虽然结构的初始化也使用了New 操作符可是结构对象依然分配在堆栈上而不是堆上，如果不使用&#8220;新建&#8221;(new)，那么在初始化所有字段之前，字段将保持未赋值状态，且对象不可用</P><br />
<P>　　2．继承性</P><br />
<P>　　结构：不能从另外一个结构或者类继承，本身也不能被继承，虽然结构没有明确的用sealed声明，可是结构是隐式的sealed .</P><br />
<P>　　类：完全可扩展的，除非显示的声明sealed 否则类可以继承其他类和接口，自身也能被继承</P><br />
<P>　　注：虽然结构不能被继承 可是结构能够继承接口，方法和类继承接口一样<BR>3．内部结构：</P><br />
<P>　　结构：</P><br />
<P>　　没有默认的构造函数，但是可以添加构造函数</P><br />
<P>　　没有析构函数</P><br />
<P>　　没?abstract 和 sealed(因为不能继承)</P><br />
<P>　　不能有protected 修饰符</P><br />
<P>　　可以不使用new 初始化</P><br />
<P>　　在结构中初始化实例字段是错误的</P><br />
<P>　　类： </P><br />
<P>　　有默认的构造函数</P><br />
<P>　　有析构函数</P><br />
<P>　　可以使用 abstract 和 sealed </P><br />
<P>　　有protected 修饰符</P><br />
<P>　　必须使用new 初始化</P><br />
<P>　　三．如何选择结构还是类</P><br />
<P>　　讨论了结构与类的相同之处和差别之后，下面讨论如何选择使用结构还是类：</P><br />
<P>　　1．堆栈的空间有限，对于大量的逻辑的对象，创建类要比创建结构好一些</P><br />
<P>　　2．结构表示如点、矩形和颜色这样的轻量对象，例如，如果声明一个含有 1000 个点对象的数组，则将为引用每个对象分配附加的内存。在此情况下，结构的成本较低。</P><br />
<P>　　3．在表现抽象和多级别的对象层次时，类是最好的选择</P><br />
<P>　　4．大多数情况下该类型只是一些数据时，结构时最佳的选择<BR><BR><BR>补充c结构和c++类的区别:<BR>C++ CLASS里的构造函数和析构函数可以在一个对象创建和销毁的时候自动执行的. <BR>结构主要是针对特定的数据进行组织的,而类是具体对象的各种属性等的集合<BR><BR></P></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.donews.com/skyfei/archive/2004/11/10/166028.aspx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
