锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久艹国产,亚洲va久久久久,国内精品久久久久影院免费http://www.shnenglu.com/zerolee/category/3014.html鎯蟲兂鑷繁5騫村悗浼?xì)鏄粈涔堟牱瀛愨︹?/description>zh-cnTue, 20 May 2008 03:30:55 GMTTue, 20 May 2008 03:30:55 GMT60緙栬瘧鏈熺殑渚濊禆鎬х郴鍒?/title><link>http://www.shnenglu.com/zerolee/archive/2007/03/29/20876.html</link><dc:creator>浠勬礇</dc:creator><author>浠勬礇</author><pubDate>Thu, 29 Mar 2007 07:02:00 GMT</pubDate><guid>http://www.shnenglu.com/zerolee/archive/2007/03/29/20876.html</guid><wfw:comment>http://www.shnenglu.com/zerolee/comments/20876.html</wfw:comment><comments>http://www.shnenglu.com/zerolee/archive/2007/03/29/20876.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zerolee/comments/commentRss/20876.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zerolee/services/trackbacks/20876.html</trackback:ping><description><![CDATA[璇ユ枃绔犲寘鎷?涓儴鍒嗐?img src ="http://www.shnenglu.com/zerolee/aggbug/20876.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zerolee/" target="_blank">浠勬礇</a> 2007-03-29 15:02 <a href="http://www.shnenglu.com/zerolee/archive/2007/03/29/20876.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>緙栬瘧鍣ㄤ綍鏃朵負(fù)浣犱駭鐢熼粯璁ゆ瀯閫犲嚱鏁?/title><link>http://www.shnenglu.com/zerolee/archive/2007/03/27/20676.html</link><dc:creator>浠勬礇</dc:creator><author>浠勬礇</author><pubDate>Tue, 27 Mar 2007 02:21:00 GMT</pubDate><guid>http://www.shnenglu.com/zerolee/archive/2007/03/27/20676.html</guid><wfw:comment>http://www.shnenglu.com/zerolee/comments/20676.html</wfw:comment><comments>http://www.shnenglu.com/zerolee/archive/2007/03/27/20676.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zerolee/comments/commentRss/20676.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zerolee/services/trackbacks/20676.html</trackback:ping><description><![CDATA[ <p class="docText"> <font face="Courier New" size="2">鎬葷粨錛?br />聽聽聽聽鏈夊洓縐嶆儏鍐碉紝浼?xì)瀵艰嚧鈥滅紪璇戝櫒蹇呴』涓烘湭澹版槑鏋勯犲嚱鏁扮殑classes鍚堟垚涓涓粯璁ゆ瀯閫犲嚱鏁扳濄侰++ 鏍囧噯鎶婇偅浜涘悎鎴愮墿縐頒負(fù)闅愬惈鐨勬湁鐢ㄩ粯璁ゆ瀯閫犲嚱鏁般傝鍚堟垚鍑烘潵鐨勬瀯閫犲嚱鏁板彧鑳芥弧瓚崇紪璇戝櫒(闈炵▼搴?鐨勯渶瑕併傚畠涔嬫墍浠ヨ兘澶熷畬鎴愪換鍔★紝鏄熺潃鈥滆皟鐢ㄦ垚鍛樺璞℃垨鍩虹被鐨勯粯璁ゆ瀯閫犲嚱鏁扳濇垨鏄滀負(fù)姣忎竴涓璞″垵濮嬪寲鍏惰櫄鍑芥暟鏈哄埗鎴栬櫄鍩虹被鏈哄埗鈥濊屽畬鎴愮殑銆傝嚦浜庢病鏈夊瓨鍦ㄩ偅鍥涚鎯呭喌鑰屽張娌℃湁澹版槑鏋勯犲嚱鏁扮殑綾伙紝鎴戜滑璇村畠浠嫢鏈夌殑鏄殣鍚殑鏃犵敤榛樿鏋勯犲嚱鏁幫紝瀹為檯涓婂畠浠茍涓嶈鍚堟垚鍑烘潵銆?br />聽聽聽聽鍦ㄥ悎鎴愮殑榛樿鏋勯犲嚱鏁頒腑錛屽彧鏈夊熀綾誨瓙瀵硅薄鍜屾垚鍛樺璞′細(xì)琚垵濮嬪寲銆傛墍鏈夊叾瀹冪殑闈為潤(rùn)鎬佹暟鎹垚鍛橈紝濡傛暣鏁般佹暣鏁版寚閽堛佹暣鏁版暟緇勭瓑絳夐兘涓嶄細(xì)琚垵濮嬪寲銆傝繖浜涘垵濮嬪寲鎿嶄綔瀵圭▼搴忚岃█鏈夐渶瑕侊紝浣嗗緙栬瘧鍣ㄨ岃█鍒欐病蹇呰銆傚鏋滅▼搴忛渶瑕佷竴涓滄妸鏌愭寚閽堣涓?鈥濈殑榛樿鏋勯犲嚱鏁幫紝閭d箞鎻愪緵瀹冪殑浜哄簲璇ユ槸紼嬪簭鍛樸?br />聽聽聽<br />聽聽聽聽C++鏂版墜涓鑸湁涓や釜甯歌鐨勮瑙o細(xì)<br />1錛変換浣曠被濡傛灉娌℃湁瀹氫箟榛樿鏋勯犲嚱鏁幫紝緙栬瘧鍣ㄥ氨浼?xì)鍚堟垚鍑哄畠鏉ャ?br />2錛夌紪璇戝櫒鍚堟垚鍑烘潵鐨勯粯璁ゆ瀯閫犲嚱鏁頒細(xì)鏄庣‘璁懼畾鈥滅被涓瘡涓涓暟鎹垚鍛樼殑榛樿鍊尖濄?br /><br />姝e浣犳墍瑙侊紝涓婅堪涓や釜娌℃湁涓涓槸鐪熺殑錛?br />-------------------------------------------------------------------------------------------<br />Summary:聽<br />聽聽聽There are four characteristics of a class under which the compiler needs to synthesize a default constructor for classes that declare no constructor at all. The Standard refers to these as implicit, nontrivial default constructors. The synthesized constructor fulfills only an implementation need. It does this by invoking member object or base class default constructors or initializing the virtual function or virtual base class mechanism for each object. Classes that do not exhibit these characteristics and that declare no constructor at all are said to have implicit, trivial default constructors. In practice, these trivial default constructors are not synthesized.</font> </p> <p class="docText"> <font face="Courier New" size="2">Within the synthesized default constructor, only the base class subobjects and member class objects are initialized. All other nonstatic data members, such as integers, pointers to integers, arrays of integers, and so on, are not initialized. These initializations are needs of the program, not of the implementation. If there is a program need for a default constructor, such as initializing a pointer to 0, it is the programmer's responsibility to provide it in the course of the class implementation.</font> </p> <p class="docText"> <font face="Courier New" size="2">Programmers new to C++ often have two common misunderstandings:<br /><br />1) </font> <span style="FONT-WEIGHT: bold"> <span style="FONT-WEIGHT: normal"> <font face="Courier New" size="2">That a default constructor is synthesized for every class that does not define one<br />2) </font> </span> <span style="FONT-WEIGHT: normal"> <font face="Courier New" size="2">That the compiler-synthesized default constructor provides explicit default initializers<br />聽聽 for each data member declared within the class</font> </span> </span> </p> <p class="docText"> <font face="Courier New" size="2">As you have seen, neither of these is true.<br /><br />--------------------------------------------------------------------------------------------<br /></font> </p> <img src ="http://www.shnenglu.com/zerolee/aggbug/20676.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zerolee/" target="_blank">浠勬礇</a> 2007-03-27 10:21 <a href="http://www.shnenglu.com/zerolee/archive/2007/03/27/20676.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>杈撳嚭瀛楃'A'/'a'鐨勮В鏋?/title><link>http://www.shnenglu.com/zerolee/archive/2007/01/15/17631.html</link><dc:creator>浠勬礇</dc:creator><author>浠勬礇</author><pubDate>Mon, 15 Jan 2007 02:59:00 GMT</pubDate><guid>http://www.shnenglu.com/zerolee/archive/2007/01/15/17631.html</guid><wfw:comment>http://www.shnenglu.com/zerolee/comments/17631.html</wfw:comment><comments>http://www.shnenglu.com/zerolee/archive/2007/01/15/17631.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zerolee/comments/commentRss/17631.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zerolee/services/trackbacks/17631.html</trackback:ping><description><![CDATA[ <font face="Courier New" size="2">杈撳嚭瀛楃'A'/'a'鐨勪唬鐮佹錛?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">聽1聽聽聽聽 </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Test1:聽Directly聽insert聽0x0A聽and聽0x41聽to聽ostream</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽2</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0x0A</span><span style="COLOR: #000000">;聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽print聽type聽int聽10</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽3</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽4</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽5</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">聽6</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0x41</span><span style="COLOR: #000000">;聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽print聽type聽int聽65,聽which聽is聽decimal聽number聽of聽'A'.</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽7</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽8</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">聽9</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Test2:聽Directly聽insert聽'\x41'聽to聽ostream</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\x41</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽'\x41'聽is聽transformed聽char,聽which聽means聽type聽char聽'A'.<br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽So,聽it聽prints聽type char 'A'聽 on screen.</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Test3:聽First聽assign聽0x41聽to聽char聽variable,聽then聽output聽it.</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">聽char_out聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0x41</span><span style="COLOR: #000000">;聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽char_out聽is聽equal聽'A'聽which聽is聽type聽int聽65.</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽char_out;聽聽聽聽聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽it聽prints聽type聽char聽'A'聽on聽screen.</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Test4:聽First聽cast聽0x0A聽to聽char,聽then聽output聽it.</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">20</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽static_cast</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0x41</span><span style="COLOR: #000000">); // it prints type char 'A' on screen.<br /></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽<br /></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /><br /></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Test5:聽Directly聽insert聽hexdecimal聽type聽number聽of聽'A'</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">24聽</span><span style="COLOR: #000000">聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽std::hex </span><span id="Codehighlighter1_748_767_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><<聽std::showbase</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0x41</span><span style="COLOR: #000000">;聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽it聽prints聽string聽literal聽"41"聽</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">25</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽std::hex聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0x0A</span><span style="COLOR: #000000">;聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽it聽prints聽type聽char 'a' on screen.<br /></span><span style="COLOR: #008080">26</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">聽int_out聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">0x41</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽int_out;聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽it聽prints聽type聽int聽8342**</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">28</span><span style="COLOR: #008000"><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #000000"><font color="#008080">29</font><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />聽聽聽聽cout聽</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">聽endl;</span></div>聽聽 0x41鏄瓧絎?A'鐨?6榪涘埗琛ㄧず鏂瑰紡錛屽畠鐨?0榪涘埗鏁版槸65錛孿x41鏄瓧絎?A'鐨勮漿涔夊瓧絎︺傝?x0A璺熷瓧絎?A'娌℃湁涓濇鍏崇郴錛岄《澶氬氨鏄?x0A鍊熺敤浜?jiǎn)瀛椊W?A'鑰屽凡銆傛晠濡傛灉鎯沖湪灞忓箷涓婅緭鍑哄瓧絎?A'鍙皢鍏惰漿涔夊瓧絎︾洿鎺ユ彃鍏ヨ緭鍑烘祦涓紝鎴栬呭皢0x41杞寲涓哄瓧絎︾被鍨嬶紝鐒跺悗鎻掑叆錛屼笉寰椾嬌鐢?x41鐩存帴鎻掑叆錛屽洜涓?x41鏈韓鏄痠nt綾誨瀷鐨?0榪涘埗鏁?5銆傚悓鏃朵篃涓嶅彲浠ュ皢'0x41'鐩存帴鎻掑叆杈撳嚭嫻侊紝鍥犱負(fù)'0x41'鏄痠nt綾誨瀷鐨勬暟銆?br />聽聽 鍙互灝濊瘯浣跨敤鎺у埗絎td::hex鏉ユ彃鍏ュ瓧絎?a'鍒拌緭鍑烘祦銆?br /></font> <img src ="http://www.shnenglu.com/zerolee/aggbug/17631.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zerolee/" target="_blank">浠勬礇</a> 2007-01-15 10:59 <a href="http://www.shnenglu.com/zerolee/archive/2007/01/15/17631.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>澶存枃浠朵腑鐨勫悕縐?/title><link>http://www.shnenglu.com/zerolee/archive/2007/01/07/17392.html</link><dc:creator>浠勬礇</dc:creator><author>浠勬礇</author><pubDate>Sun, 07 Jan 2007 07:00:00 GMT</pubDate><guid>http://www.shnenglu.com/zerolee/archive/2007/01/07/17392.html</guid><wfw:comment>http://www.shnenglu.com/zerolee/comments/17392.html</wfw:comment><comments>http://www.shnenglu.com/zerolee/archive/2007/01/07/17392.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.shnenglu.com/zerolee/comments/commentRss/17392.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zerolee/services/trackbacks/17392.html</trackback:ping><description><![CDATA[ <p> <font face="Courier New" size="2">璧勬枡鏁寸悊浜庛婂ぇ瑙勬āC++紼嬪簭璁捐銆嬄犅犅?br />聽聽聽鍦ㄥご鏂囦歡鐨勬枃浠朵綔鐢ㄥ煙涓0鏄庣殑鍚嶇О錛屽彲鑳芥綔鍦ㄥ湴涓庢暣涓郴緇熶腑浠諱綍涓涓枃浠剁殑鏂囦歡浣滅敤鍩熷悕縐板啿紿併傚嵆浣垮湪涓涓?cpp鏂囦歡鐨勬枃浠朵綔鐢ㄥ煙涓0鏄庣殑甯︽湁鍐呴儴榪炴帴鐨勫悕縐頒篃涓嶈兘淇濊瘉涓瀹氫笉涓?h鏂囦歡鐨勪綔鐢ㄥ煙鍚嶇О鍐茬獊銆?br />聽聽聽涓昏璁捐瑙勫垯錛?font color="#ff0000">鍙湁綾匯佺粨鏋勩佽仈鍚堝拰鑷敱榪愮畻絎﹀嚱鏁板簲璇ュ湪.h鏂囦歡浣滅敤鍩熷唴澹版槑錛涘彧鏈夌被銆佺粨鏋勩佽仈鍚堝拰鍐呰仈鍑芥暟鎴愬憳鎴栵紙鍐呰仈錛夎嚜鐢辮繍綆楃搴旇鍦?h鏂囦歡鐨勪綔鐢ㄥ煙鍐呭畾涔夈?br /></font>聽聽聽浠ヤ笅浠g爜孌甸槓榪頒簡(jiǎn)涓婅堪璁捐瑙勫垯銆?/font> </p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">聽<font face="Courier New" size="2">1</font></span> <font face="Courier New" size="2"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Driver.h聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:comment</span> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">聽2</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">#ifndef聽I(yíng)NCLUDED_DRIVER聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:internal聽include聽guard</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">聽3</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">#define</span> <span style="COLOR: #000000">聽I(yíng)NCLUDED_DIRVER</span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">聽4</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <br /> </span> <span style="COLOR: #008080">聽5</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />#ifndef聽I(yíng)NCLUDED_NIFTY聽聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:redundant聽include聽guard</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">聽6</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">#include聽</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">nifty.h</span> <span style="COLOR: #000000">"</span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">聽7</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">#endif</span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">聽8</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <br /> </span> <span style="COLOR: #008080">聽9</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">#define</span> <span style="COLOR: #000000">聽PI聽3.141592聽聽聽聽聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Avoid:macro聽constant</span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">10</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">#define</span> <span style="COLOR: #000000">聽MIN(X)聽((X)<(Y)?(X):(Y))聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Avoid:macro聽constant</span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">11</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <br /> </span> <span style="COLOR: #008080">12</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">class</span> <span style="COLOR: #000000">聽ostream;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽class聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">13</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">struct</span> <span style="COLOR: #000000">聽DriverInit;聽聽聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽class聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">14</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">union聽Uaw;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽class聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">15</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">16</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">extern</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽globalVariable;聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Avoid:external聽data聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">17</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">static</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽fileScopeVariable;聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Avoid:internal聽data聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">18</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">const</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽BUFFER_SIZE聽</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">256</span> <span style="COLOR: #000000">;聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Avoid:const聽data聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">19</span> <span style="COLOR: #008000"> <img id="Codehighlighter1_669_681_Open_Image" onclick="this.style.display='none'; Codehighlighter1_669_681_Open_Text.style.display='none'; Codehighlighter1_669_681_Closed_Image.style.display='inline'; Codehighlighter1_669_681_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> <img id="Codehighlighter1_669_681_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_669_681_Closed_Text.style.display='none'; Codehighlighter1_669_681_Open_Image.style.display='inline'; Codehighlighter1_669_681_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /> </span> <span style="COLOR: #0000ff">enum</span> <span style="COLOR: #000000">聽Boolean聽</span> <span id="Codehighlighter1_669_681_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"> </span> <span id="Codehighlighter1_669_681_Open_Text"> <span style="COLOR: #000000">{聽zero,聽one聽}</span> </span> <span style="COLOR: #000000">;聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Avoid:enumeration聽at聽file聽scope</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">20</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">typedef聽</span> <span style="COLOR: #0000ff">long</span> <span style="COLOR: #000000">聽BigInt;聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽typedef聽at聽file聽scope</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">21</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">22</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_788_1419_Open_Image" onclick="this.style.display='none'; Codehighlighter1_788_1419_Open_Text.style.display='none'; Codehighlighter1_788_1419_Closed_Image.style.display='inline'; Codehighlighter1_788_1419_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> <img id="Codehighlighter1_788_1419_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_788_1419_Closed_Text.style.display='none'; Codehighlighter1_788_1419_Open_Image.style.display='inline'; Codehighlighter1_788_1419_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /> </span> <span style="COLOR: #0000ff">class</span> <span style="COLOR: #000000">聽Driver聽</span> <span id="Codehighlighter1_788_1419_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"> </span> </font> </font> <span id="Codehighlighter1_788_1419_Open_Text"> <span style="COLOR: #000000"> <font face="Courier New" size="2">{<br /></font> </span> <span style="COLOR: #008080">23</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_804_817_Open_Image" onclick="this.style.display='none'; Codehighlighter1_804_817_Open_Text.style.display='none'; Codehighlighter1_804_817_Closed_Image.style.display='inline'; Codehighlighter1_804_817_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /> <img id="Codehighlighter1_804_817_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_804_817_Closed_Text.style.display='none'; Codehighlighter1_804_817_Open_Image.style.display='inline'; Codehighlighter1_804_817_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />聽聽聽</span> <font face="Courier New"> <font size="2"> <span style="COLOR: #0000ff">enum</span> <span style="COLOR: #000000">聽Color聽</span> <span id="Codehighlighter1_804_817_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"> </span> <span id="Codehighlighter1_804_817_Open_Text"> <span style="COLOR: #000000">{聽RED,聽GREEN聽}</span> </span> <span style="COLOR: #000000">;聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:enumeration聽in聽class聽scope</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">24</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #000000">聽聽聽typedef聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽(Dirver::</span> <span style="COLOR: #000000">*</span> <span style="COLOR: #000000">PMF)();聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽typedef聽in聽class聽scope</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">25</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #000000">聽聽聽</span> <span style="COLOR: #0000ff">static</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽s_count;聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:static聽member聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">26</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #000000">聽聽聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽d_size;聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽member聽data聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">27</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">28</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #0000ff">private</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">:<br /></span> <span style="COLOR: #008080">29</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_1043_1127_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1043_1127_Open_Text.style.display='none'; Codehighlighter1_1043_1127_Closed_Image.style.display='inline'; Codehighlighter1_1043_1127_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /> <img id="Codehighlighter1_1043_1127_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1043_1127_Closed_Text.style.display='none'; Codehighlighter1_1043_1127_Open_Image.style.display='inline'; Codehighlighter1_1043_1127_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />聽聽聽</span> <span style="COLOR: #0000ff">struct</span> <span style="COLOR: #000000">聽Pnt聽</span> <span id="Codehighlighter1_1043_1127_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"> </span> </font> </font> <span id="Codehighlighter1_1043_1127_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">30</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽聽聽聽</span> <span style="COLOR: #0000ff">short</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">int</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽d_x,聽d_y;<br /></span> <span style="COLOR: #008080">31</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽聽聽聽Pnt(</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽x,聽</span> <span style="COLOR: #0000ff">int</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽y)聽<br /></span> <span style="COLOR: #008080">32</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_1120_1122_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1120_1122_Open_Text.style.display='none'; Codehighlighter1_1120_1122_Closed_Image.style.display='inline'; Codehighlighter1_1120_1122_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /> <img id="Codehighlighter1_1120_1122_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1120_1122_Closed_Text.style.display='none'; Codehighlighter1_1120_1122_Open_Image.style.display='inline'; Codehighlighter1_1120_1122_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />聽聽聽聽聽聽聽:聽d_x(x),聽d_y(y)聽</span> <span id="Codehighlighter1_1120_1122_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"> </span> <span id="Codehighlighter1_1120_1122_Open_Text"> <span style="COLOR: #000000">{聽}</span> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">33</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />聽聽聽}</span> </font> </font> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;聽聽聽聽聽聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽private聽struct聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">34</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #000000">聽聽聽friend聽DirverInit;聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽friend聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">35</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">36</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #0000ff">public</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">:<br /></span> <span style="COLOR: #008080">37</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">static</span> <span style="COLOR: #000000">聽round(</span> <span style="COLOR: #0000ff">double</span> <span style="COLOR: #000000">聽d);聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:static聽member聽function聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">38</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #000000">聽聽聽</span> <span style="COLOR: #0000ff">void</span> <span style="COLOR: #000000">聽setSize(</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽size);聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽member聽function聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">39</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #000000">聽聽聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽cmp(</span> <span style="COLOR: #0000ff">const</span> <span style="COLOR: #000000">聽Driver</span> <span style="COLOR: #000000">&</span> <span style="COLOR: #000000">)聽</span> <span style="COLOR: #0000ff">const</span> <span style="COLOR: #000000">;聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽const聽member聽function聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">40</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span> <span style="COLOR: #000000">}</span> </font> </font> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽class聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">41</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">42</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_1481_1492_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1481_1492_Open_Text.style.display='none'; Codehighlighter1_1481_1492_Closed_Image.style.display='inline'; Codehighlighter1_1481_1492_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> <img id="Codehighlighter1_1481_1492_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1481_1492_Closed_Text.style.display='none'; Codehighlighter1_1481_1492_Open_Image.style.display='inline'; Codehighlighter1_1481_1492_Open_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /> </span> <span style="COLOR: #0000ff">static</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">class</span> <span style="COLOR: #000000">聽DriverInit聽</span> <span id="Codehighlighter1_1481_1492_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"> </span> </font> </font> <span id="Codehighlighter1_1481_1492_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">43</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">44</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span> <span style="COLOR: #000000">}</span> </font> </font> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽DriverInit;聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Special聽class</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">45</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">46</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽min(</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽x,聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽y);聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Avoid:聽free聽function聽dec.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">47</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">48</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />inline聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽max(</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽x,聽</span> <span style="COLOR: #0000ff">int</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽y)<br /></span> <span style="COLOR: #008080">49</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_1609_1636_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1609_1636_Open_Text.style.display='none'; Codehighlighter1_1609_1636_Closed_Image.style.display='inline'; Codehighlighter1_1609_1636_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> </span> </font> </font> <span id="Codehighlighter1_1609_1636_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">50</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽</span> <span style="COLOR: #0000ff">return</span> <span style="COLOR: #000000">聽x聽</span> <span style="COLOR: #000000">></span> <span style="COLOR: #000000">聽y聽</span> <span style="COLOR: #000000">?</span> </font> </font> <span style="COLOR: #000000"> <font face="Courier New" size="2">聽x聽:聽y;<br /></font> </span> <span style="COLOR: #000000"> <font face="Courier New" color="#008080" size="2">51聽聽聽 </font>}</span> </span> <span style="COLOR: #000000">聽聽聽</span> <font face="Courier New" size="2"> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽Avoid聽free聽inline聽function聽def.</span> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">52</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">53</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />inline聽</span> <span style="COLOR: #0000ff">void</span> <span style="COLOR: #000000">聽Driver::setSize(</span> <span style="COLOR: #0000ff">int</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽size)聽<br /></span> <span style="COLOR: #008080">54</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_1715_1735_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1715_1735_Open_Text.style.display='none'; Codehighlighter1_1715_1735_Closed_Image.style.display='inline'; Codehighlighter1_1715_1735_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> </span> </font> </font> <span id="Codehighlighter1_1715_1735_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">55</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽d_size聽</span> <span style="COLOR: #000000">=</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽size;<br /></span> <span style="COLOR: #008080">56</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span> </font> </font> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽inline聽member聽function聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">57</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">58</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />ostream</span> <span style="COLOR: #000000">&</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">operator</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000"><<</span> <span style="COLOR: #000000">(ostream</span> <span style="COLOR: #000000">&</span> <span style="COLOR: #000000">聽o,聽</span> <span style="COLOR: #0000ff">const</span> <span style="COLOR: #000000">聽Dirver</span> <span style="COLOR: #000000">&</span> <span style="COLOR: #000000">聽d);聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽free聽operator聽function聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">59</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">60</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />inline聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #0000ff">operator</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">==</span> <span style="COLOR: #000000">(</span> <span style="COLOR: #0000ff">const</span> <span style="COLOR: #000000">聽Driver</span> <span style="COLOR: #000000">&</span> <span style="COLOR: #000000">聽lhs,聽</span> <span style="COLOR: #0000ff">const</span> <span style="COLOR: #000000">聽Dirver</span> <span style="COLOR: #000000">&</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽rhs)聽<br /></span> <span style="COLOR: #008080">61</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_1930_1966_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1930_1966_Open_Text.style.display='none'; Codehighlighter1_1930_1966_Closed_Image.style.display='inline'; Codehighlighter1_1930_1966_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> </span> </font> </font> <span id="Codehighlighter1_1930_1966_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">62</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽</span> <span style="COLOR: #0000ff">return</span> <span style="COLOR: #000000">聽compare(lhs,聽rhs)聽</span> <span style="COLOR: #000000">==</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">0</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;<br /></span> <span style="COLOR: #008080">63</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span> </font> </font> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽free聽inline聽operator聽func.聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">64</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">65</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />inline聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">聽Driver::round(</span> <span style="COLOR: #0000ff">double</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽d)<br /></span> <span style="COLOR: #008080">66</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_2048_2098_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2048_2098_Open_Text.style.display='none'; Codehighlighter1_2048_2098_Closed_Image.style.display='inline'; Codehighlighter1_2048_2098_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> </span> </font> </font> <span id="Codehighlighter1_2048_2098_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">67</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽retrun聽d聽</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">0</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">?</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">-</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">(</span> <span style="COLOR: #000000">0.5</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">-</span> <span style="COLOR: #000000">聽d)聽:聽</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">(</span> <span style="COLOR: #000000">0.5</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">+</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽d);<br /></span> <span style="COLOR: #008080">68</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span> </font> </font> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽聽聽聽</span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽fine:聽inline聽static聽member聽func.聽def.</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">69</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">70</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">#endif</span> </font> </font> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">71</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <br /> </span> <span style="COLOR: #008080">72</span> </font> </font> <span style="COLOR: #000000"> <font face="Courier New" size="2"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </font> </span> </div> <img src ="http://www.shnenglu.com/zerolee/aggbug/17392.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zerolee/" target="_blank">浠勬礇</a> 2007-01-07 15:00 <a href="http://www.shnenglu.com/zerolee/archive/2007/01/07/17392.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>The Return Value Optimization[2]http://www.shnenglu.com/zerolee/archive/2006/11/13/15137.html浠勬礇浠勬礇Mon, 13 Nov 2006 11:36:00 GMThttp://www.shnenglu.com/zerolee/archive/2006/11/13/15137.htmlhttp://www.shnenglu.com/zerolee/comments/15137.htmlhttp://www.shnenglu.com/zerolee/archive/2006/11/13/15137.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/15137.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/15137.html ------->
Without any optimization, the compile-generated(pseduo) code for Complex_Add() is

聽1 void 聽Complex_Add( const 聽Complex & 聽__tempResult,聽 const 聽Complex & 聽c1,聽 const 聽Complex & 聽c2)
聽2
{
聽3 聽聽聽 struct
聽Complex聽retVal;
聽4 聽聽聽retVal.Complex::Complex();聽 // 聽Constructor聽retval

聽5 聽聽聽retVal.real聽 = 聽a.real聽 + 聽b.real;
聽6 聽聽聽retVal.imag聽 = 聽a.imag聽 +
聽b.imag;
聽7 聽聽聽__tempResult.Complex::Complex(retVal);聽 // 聽copy-constructor

聽8 聽聽retVal.Complex:: ~ Complex();聽 // 聽destroy聽retVal
聽9 聽聽 return ;
10 }
The compiler can optimize Complex_Add() by eliminating the local object retVal and replacing it with __tempResult. This is the Return Value Optimization:
1 void 聽Complex_Add( const 聽Complex & 聽__tempResult,聽 const 聽Complex & 聽c1,聽 const 聽Complex & 聽c2)
2
{
3 聽聽聽__tempResult.Complex::Complex();聽聽 // 聽construcotr聽__tempResult

4 聽聽聽__tempResult.real聽 = 聽a.real聽 + 聽b.real;
5 聽聽聽__tempResult.imag聽 = 聽a.imag聽 +
聽b.imag;
6 聽聽聽 return
;
7 }
The RVO eliminated the local retVal object and therefore saved us a constructor as well as a destructor computation.
To get a numerical feel for all this efficiency discussion, we measured the impact of RVO on execution speed. We coded two versions of operator +(), one of which was optimized and the other not. The measured code consisted of a million loop iterations:
聽1 int 聽main()
聽2
{
聽3 聽聽聽Complex聽a( 1 , 0
);
聽4 聽聽聽Complex聽b( 2 , 0
);
聽5
聽聽聽Complex聽c;
聽6 聽聽聽 // 聽begin聽timing聽here

聽7 聽聽聽 for 聽( int 聽i聽 = 1000000 ;聽i聽 > 0 ;聽 -- i)聽 {
聽8 聽聽聽聽聽聽c聽 = 聽a聽 +
聽b;
聽9 聽聽聽}

10 聽聽聽 // 聽stoping聽timing聽here
11 }
The second version, without RVO, executed in 1.89 seconds. The first version, with RVO applied was much faster --1.30 seconds.

Compiler optimizations, naturally, must preserve the correctness of the original computation. In the case of the RVO, this is not always easy. Since the RVO is not mandatory, the compiler will not perform it on comlicated functions. For example, if the function has multiple return statements returning objects of different names, RVO will not be applied. You must return the same named object to have a chance at the RVO.
One compiler we tested refused to apply the RVO to this particular version of operator +:
1Complex聽operator+(const聽Complex&聽a,聽const聽Complex&聽b)
2{
3聽聽聽//聽operator聽+聽version聽1
4聽聽聽Complex聽retVal;
5聽聽聽retVal.real聽=聽a.real聽+聽b.real;
6聽聽聽retVal.imag聽=聽a.imag聽+聽b.imag;
7聽聽聽return聽retVal;
8}
It did, however, apply the RVO to this version:
1Complex聽operator+(const聽Complex&聽a,聽const聽Complex&聽b)
2{
3聽聽聽//聽operator聽+聽version聽2
4聽聽聽double聽r聽=聽a.real聽+聽b.real;
5聽聽聽double聽i聽=聽a.imag聽+聽b.imag;
6聽聽聽return聽Complex(r,聽i);
7}

8聽聽聽
We speculated that the difference may lie in the fact that Version 1 used a named variable(retVal) as a return value whereas Version 2 used an unnamed variable. Version 2 used a constructor call in the return statement but never named it. It may be the case that this particular compiler implementation chose to avoid optimizing away named variables.
Our speculation was boosted by some additional evidence. We tested two more versions of operator +:
聽1Complex聽operator+(const聽Complex&聽a,聽const聽Complex&聽b)
聽2{
聽3聽聽聽//聽operator聽+聽version聽3
聽4聽聽聽Complex聽retVal(a.real聽+聽b.real,聽a.imag聽+聽b.imag);
聽5聽聽聽return聽retVal;
聽6}

聽7and
聽8Complex聽operator+(const聽Complex&聽a,聽const聽Complex&聽b)
聽9{
10聽聽聽//聽operator聽+聽version聽4
11聽聽聽return聽Complex(a.real聽+聽b.real,聽a.imag聽+聽b.imag);
12}
As speculated, the RVO was applied to Version 4 but not to Version 3.
In addition, you must also define a copy constructor to "Turn on" the Return Value Optimization. If the class involved does not have a copy constructor defined, the RVO is quietly turned off.

Key Points:
[1] If you聽must return an object by value, the Return Value Optimization will help performance by eliminating the nedd for creation and destruction of a local object.

[2] The application of the RVO is up to the direction of the compiler implementation. You need to consult your compile documentation or experiment to find if and when RVO is applied.

[3] You will have a better shot at RVO by deploying the computational constructor.


浠勬礇 2006-11-13 19:36 鍙戣〃璇勮
]]>
The Return Value Optimization[1]http://www.shnenglu.com/zerolee/archive/2006/11/13/15136.html浠勬礇浠勬礇Mon, 13 Nov 2006 11:01:00 GMThttp://www.shnenglu.com/zerolee/archive/2006/11/13/15136.htmlhttp://www.shnenglu.com/zerolee/comments/15136.htmlhttp://www.shnenglu.com/zerolee/archive/2006/11/13/15136.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/15136.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/15136.html Resource from the book:
Dov Bulka & David Mayhew <Efficient C++--- Performance programming Techiques>

Anytime you can skip the creation and destruction of an object, you are looking at a performance gain. We will discuss an optimization often performed by compilers to speed聽 up your source code by transforming it and eliminating object creation. This optimization is referred to as the Return Value Optimization(RVO). Prior to delving into the RVO we need to understand how return-by-value works. We will walk through it with a simple example.

The Mechanics of Return-by-Value
The Complex class implements a representation for complex numbers:

聽1 class 聽Complex
聽2
{
聽3 聽聽聽 // 聽Complex聽addition聽operator

聽4 聽聽聽 friend聽Complex聽 operator + ( const 聽Complex & ,聽 const 聽Complex & );
聽5 public
:
聽6 聽聽聽 //
聽default聽constructor
聽7 聽聽聽 //
聽Value聽defaults聽to聽0聽unless聽otherwise聽specified
聽8 聽聽聽 Complex( double 聽r聽 = 0.0 ,聽 double 聽i聽 = 0.0 ):real(r),聽imag(i)聽 {聽}

聽9
10 聽聽聽 // 聽copy聽constructor

11 聽聽聽 Complex( const 聽Complex & 聽c):real(c.real),聽imag(c.imag)聽 {聽}
12
13 聽聽聽 // 聽Assignment聽operator

14 聽聽聽 Complex & operator = ( const 聽Complex & 聽c);
15

16 聽聽聽 ~ Complex()聽 {聽}

17 private :
18 聽聽聽 double
聽real;
19 }
;
The addition operator returns a Complex object by value, as in:
1 Complex聽 operator + ( const 聽Complex & 聽a,聽 const 聽Complex & 聽b)
2
{
3
聽聽聽聽Complex聽retVal;
4 聽聽聽聽retVal.real聽 = 聽a.real聽 +
聽b.real;
5 聽聽聽聽retVal.imag聽 = 聽a.imag聽 +
聽b.imag;
6 聽聽聽聽 return
聽retVal;
7 }
Suppose c1, c2, and c3 are Complex and we excute
c3 = c1 + c2;
How do we get the value of c1 + c2 into c3? One popular technique used by compilers is to create a temporary __result object and pass it into Complex::operator +() as a third argument. It is passed by referece. So the compiler rewrites
1 Complex & 聽Complex:: operator + ( const 聽Complex & 聽c1,聽 const 聽Complex & 聽c2)
2
{
3
聽聽
4 }
into a slightly different function:
1 void 聽Complex_Add( const 聽Complex & 聽__result,聽 const 聽Complex & 聽c1,聽 const 聽Complex & 聽c2)
2
{
3
聽聽聽
4 }
Now the original source statement
c3 = c1 + c2;
is transformed into(pseudocode):
1 struct 聽Complex聽__tempResult;聽 // 聽Storage.聽No聽constructor聽here.
2 Complex_Add(__tempResult,聽c1,聽c2);聽 // 聽All聽argument聽passed聽by聽reference.
3 c3聽 = 聽__tempResult;聽 // 聽Feed聽result聽back聽into聽left-hand-side.
This return-by-value implementation opens up an optimization opportunity by eliminating the local object RetVal(inside operator +()) and computing the return value directly into the __tempResult temporary object. This is the Return Value Optimization.

浠勬礇 2006-11-13 19:01 鍙戣〃璇勮
]]>
Template and Inheritancehttp://www.shnenglu.com/zerolee/archive/2006/11/13/15124.html浠勬礇浠勬礇Mon, 13 Nov 2006 05:37:00 GMThttp://www.shnenglu.com/zerolee/archive/2006/11/13/15124.htmlhttp://www.shnenglu.com/zerolee/comments/15124.htmlhttp://www.shnenglu.com/zerolee/archive/2006/11/13/15124.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/15124.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/15124.html As Meyers noted in Item 24 of Effective C++,the inability to inline a virtual function is its biggest performace penalty.
Virtual functions seems to inflict a performace cost in several ways:
[1] The vptr must be initialized in the constructor.
[2] A virtual function is invoked via pointer indirection. We must fetch the pointer to the function table and then access the correct function offset.
[3] Inlining is a compile-time decision. The compiler cannot inline virtual functions whose resolution takes place at run-time.
The true cost of virtual functions then boils down to the third item only.

-------------------------------------------------------------------------------------------
Virtual function calls that can be resolved only at rum-time will inhibit inling. At times, that may pose a performace problem that we must solve. Dynamic binding of聽a function call is a consequence of inheritance. One way to eliminate dyanamic binding is to replace inheritance with a template-based design. Templates are more performance-friendly in the sense that they push the resolution step from run-time to compile-time. Compile-time, as far as we are concerned, is free.

The desing space for inheritance and templates has some overlap. We will discuss one such example.

Suppose you wanted to develop a thread-safe string class that may be manipulated safely by concurrent threads in a Win32 environment. In that environment you have a choice of multiple synchronization schemes such ascriticalsection, mutex, and semanphores, just to name a few. You would like your thread-safe string to offer the flexibility to use any of those schemes, and at different times you may have a reason to prefer one scheme over another. Inheritance would be a reasonable choice to capture the commonality among synchronization mechanisms.

The Locker abstract base class will declare the common interface:

聽1 class 聽Locker
聽2 {
聽3 public :
聽4 聽聽聽聽Locker()聽 {聽}
聽5 聽聽聽聽 virtual ~ Locker()聽 {聽}
聽6 聽聽聽聽 virtual void lock ()聽 = 0 ;
聽7 聽聽聽聽 virtual void 聽unlock()聽 = 0 ;
聽8 }
;
聽9
10 class 聽CriticalSectionLock聽:聽 public 聽Locker
11 {聽
12
13 }
;
14 class 聽MutexLock聽:聽 public 聽Locker
15 {
16
17 }
;
Because you prefer not to re-invent the wheel, you made the choice to derive the thread-safe string from the existing standard string. The remaining design choices are:

[1] Hard coding. You could derive three distinct classes from string::CriticalSectionString, MutexString, and SemaphoreString, each class implementing its implied synchronization mechanism.
[2] Inheritance. You could derive a single ThreadSafeString class that contains a pointer to a Locker object. Use polynorphism to select the particular synchronization mechanism at run-time.
[3] Templates. Create a template-based string class parameterized by the Locker type.
////////////////////////////////////////////////////////////////////////////////////////////
Here we only talk about the Template implementation.

The templates-based design combines the best of both worlds-reuse and efficiency. The ThreadSafeString is implemented as a聽template parameterized by the Locker template argument:
聽1template聽<class聽LOCKER>
聽2class聽ThreadSafeString聽:聽publicstring
聽3{
聽4public:
聽5聽聽聽ThreadSafeString(constchar*聽s)聽
聽6聽聽聽:聽string(s)聽{聽}
聽7聽聽聽
聽8聽聽聽int聽length();
聽9private:
10聽聽聽LOCKER聽lock;
11}
;
12
The length method implementation is similar to the previous ones:
聽1template聽<class聽LOCKER>
聽2inline
聽3int聽ThreadSafeString<LOCKER>聽::聽length()
聽4{
聽5聽聽lock.lock();
聽6聽聽int聽len聽=string::length();
聽7聽聽lock.unlock();
聽8
聽9聽聽return聽len;
10}
If you want critical section protection, you will instantiate the template with a CriticalSectionLock:
{
聽聽 ThreadSafeString<CriticalSectionLock> csString = "Hello";
聽聽 ...
}
or you may go with a mutex:
{
聽聽 ThreadSafeString<MutexLock> mtxString = "Hello";
聽聽 ...
}

This design also provides a relief from the virtual function calls to lock() and unlock(). The declaration of a ThreadSafeString selects a particular type of synchronization upon template instantiation time. Just like hard coding, this enables the compiler to resolve the virtual calls and inline them.

As you聽can see, templates can make a positive performace contribution by pushing computations out of the excution-time and into compile-time, enabling inling in the process.


浠勬礇 2006-11-13 13:37 鍙戣〃璇勮
]]>
鍏充簬vector鐨勪嬌鐢?/title><link>http://www.shnenglu.com/zerolee/archive/2006/10/14/13671.html</link><dc:creator>浠勬礇</dc:creator><author>浠勬礇</author><pubDate>Sat, 14 Oct 2006 07:05:00 GMT</pubDate><guid>http://www.shnenglu.com/zerolee/archive/2006/10/14/13671.html</guid><wfw:comment>http://www.shnenglu.com/zerolee/comments/13671.html</wfw:comment><comments>http://www.shnenglu.com/zerolee/archive/2006/10/14/13671.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zerolee/comments/commentRss/13671.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zerolee/services/trackbacks/13671.html</trackback:ping><description><![CDATA[ <p> <font face="Courier New" size="2"> <font color="#ff1493">Item1: vector鐨勪嬌鐢?/font> <br /> <font color="#006400">JG闂</font>錛?br />void f(vector<int>& v) {<br />聽聽聽v[0] = 1;聽聽聽// A<br />聽聽 v[1] = 2;聽聽聽// B<br />}<br /><font color="#006400">GURU闂</font>:</font> </p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 342px; BACKGROUND-COLOR: #eeeeee"> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">聽1</span> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #000000">vector</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">></span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽v;<br /></span> <span style="COLOR: #008080">聽2</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />v.reserve(</span> <span style="COLOR: #000000">2</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">);<br /></span> <span style="COLOR: #008080">聽3</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />assert(v.capacity()聽</span> <span style="COLOR: #000000">==</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">2</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">);<br /></span> <span style="COLOR: #008080">聽4</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />v[</span> <span style="COLOR: #000000">0</span> <span style="COLOR: #000000">]聽</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">1</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;<br /></span> <span style="COLOR: #008080">聽5</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />v[</span> <span style="COLOR: #000000">1</span> <span style="COLOR: #000000">]聽</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">2</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;<br /></span> <span style="COLOR: #008080">聽6</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">for</span> <span style="COLOR: #000000">聽(vector</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">></span> <span style="COLOR: #000000">::iterator聽i聽</span> <span style="COLOR: #000000">=</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽v.begin();聽<br /></span> <span style="COLOR: #008080">聽7</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_144_170_Open_Image" onclick="this.style.display='none'; Codehighlighter1_144_170_Open_Text.style.display='none'; Codehighlighter1_144_170_Closed_Image.style.display='inline'; Codehighlighter1_144_170_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />聽聽聽聽聽聽聽i聽</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #000000">聽v.end();聽i</span> <span style="COLOR: #000000">++</span> <span style="COLOR: #000000">)聽</span> <span id="Codehighlighter1_144_170_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"> </span> </font> </font> <span id="Codehighlighter1_144_170_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">聽8</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽聽cout聽</span> <span style="COLOR: #000000"><<</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">*</span> <span style="COLOR: #000000">i聽</span> <span style="COLOR: #000000"><<</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽endl;<br /></span> <span style="COLOR: #008080">聽9</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span> </font> </font> </span> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">10</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />cout聽</span> <span style="COLOR: #000000"><<</span> <span style="COLOR: #000000">聽v[</span> <span style="COLOR: #000000">0</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">];<br /></span> <span style="COLOR: #008080">11</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />v.reserve(</span> <span style="COLOR: #000000">100</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">);<br /></span> <span style="COLOR: #008080">12</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />assert(v.capacity()聽</span> <span style="COLOR: #000000">==</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">100</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">);<br /></span> <span style="COLOR: #008080">13</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />cout聽</span> <span style="COLOR: #000000"><<</span> <span style="COLOR: #000000">聽v[</span> <span style="COLOR: #000000">0</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">];<br /></span> <span style="COLOR: #008080">14</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />v[</span> <span style="COLOR: #000000">2</span> <span style="COLOR: #000000">]聽</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">聽聽</span> <span style="COLOR: #000000">3</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;<br /></span> <span style="COLOR: #008080">15</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />v[</span> <span style="COLOR: #000000">3</span> <span style="COLOR: #000000">]聽</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">4</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;<br /></span> <span style="COLOR: #008080">16</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">聽...</span> </font> </font> <span style="COLOR: #008000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">17</span> <span style="COLOR: #008000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">v[</span> <span style="COLOR: #000000">99</span> <span style="COLOR: #000000">]聽</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">100</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;<br /></span> <span style="COLOR: #008080">18</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff">for</span> <span style="COLOR: #000000">聽(vector</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">></span> <span style="COLOR: #000000">::iterator聽i聽</span> <span style="COLOR: #000000">=</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽v.begin();<br /></span> <span style="COLOR: #008080">19</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_353_379_Open_Image" onclick="this.style.display='none'; Codehighlighter1_353_379_Open_Text.style.display='none'; Codehighlighter1_353_379_Closed_Image.style.display='inline'; Codehighlighter1_353_379_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />聽聽聽聽聽聽聽i聽</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #000000">聽v.end();聽i</span> <span style="COLOR: #000000">++</span> <span style="COLOR: #000000">)聽</span> <span id="Codehighlighter1_353_379_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"> </span> </font> </font> <span id="Codehighlighter1_353_379_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">20</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽聽cout聽</span> <span style="COLOR: #000000"><<</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">*</span> <span style="COLOR: #000000">i聽</span> <span style="COLOR: #000000"><<</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽endl;<br /></span> <span style="COLOR: #008080">21</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span> </font> </font> </span> </div> <font face="Courier New" size="2">瀵逛簬浠ヤ笂涓や釜闂錛屽彲鑳藉瓨鍦ㄥ涓嬬殑寤鴻錛?br />1) JG闂涓瑽涓嶢鐨勫尯鍒?br />聽聽 濡傛灉V闈炵┖錛屽垯A涓嶣鏃犱換浣曞尯鍒紝濡傛灉V涓虹┖錛屽垯B琛屽皢涓瀹氫細(xì)鎶涘嚭涓涓猻td::out_of_range寮傚父錛岃嚦浜嶢鐨勮涓猴紝鏍囧噯騫舵湭鍔犱換浣曡鏄庛?br />聽聽 鍘熷洜鍦ㄤ簬錛歛t()鎴愬憳鍑芥暟浼?xì)瀵瑰叾杩涜瓒婄晫妫鏌ワ紝鑰宱perator[]鎿嶄綔絎﹀垯涓嶄細(xì)錛岀鎵夸簬鏁扮粍[]涓嬫爣榪愮畻絎︿篃涓嶄細(xì)媯(gè)鏌ヨ秺鐣屼竴鏍楓?br /><br />2) GURU闂<br />浠g爜錛?br /></font> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 41px; BACKGROUND-COLOR: #eeeeee"> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">1</span> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #000000">vector</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">></span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽v;<br /></span> <span style="COLOR: #008080">2</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />v.reserve(</span> <span style="COLOR: #000000">2</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">);<br /></span> <span style="COLOR: #008080">3</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />assert(v.capacity()聽</span> <span style="COLOR: #000000">==</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">2</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">);<br /></span> <span style="COLOR: #008080">4</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> </div> <font face="Courier New" size="2">聽1> 鏂█鍙兘浼?xì)澶辫触銆俽eserve()鍑芥暟鐨勮皟鐢ㄤ細(xì)淇濊瘉v鐨勫閲忚嚦灝戜負(fù)2錛屼篃鍙兘澶т簬2錛岃屼笖瀹歸噺鏄憟鎸囨暟閫熷害涓婂崌鐨勩傚簲璇ユ敼涓篴ssert(v.capacity() >= 2);<br />聽2> 浣嗘槸鏀硅繘鍚庣殑鏂█鏄劇殑鏈夌偣澶氫綑銆傚洜涓烘爣鍑嗗凡淇濊瘉鏂█鐨勫唴瀹癸紝鍐欎笂鍙細(xì)甯︽潵涓嶅繀瑕佺殑娣蜂貢錛岄櫎闈炰笉鐩鎬俊鏍囧噯銆?br />浠g爜錛?br /></font> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">1</span> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #000000">v[</span> <span style="COLOR: #000000">0</span> <span style="COLOR: #000000">]聽</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">1</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;<br /></span> <span style="COLOR: #008080">2</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />v[</span> <span style="COLOR: #000000">1</span> <span style="COLOR: #000000">]聽</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">2</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">;<br /></span> <span style="COLOR: #008080">3</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> </div> <font face="Courier New" size="2">聽 size 鈥斺?gt;resize, capacity 鈥斺?gt; reserve<br />1> size鍛婅瘔浣犲鍣ㄤ腑鐩墠瀹為檯鏈夊灝戝厓绱狅紝鑰屽搴旂殑resize浼?xì)鍦ㄥ鍣ㄧ殑灏鹃儴娣诲姞鎴栧垹闄や竴浜涘厓绱狅紝鏉ヨ皟鏁村鍣ㄥ綋涓殑瀹為檯鍐呭錛屼嬌瀹瑰櫒杈懼埌鎸囧畾澶у皬銆傚list銆乨eque鍜寁ector閫傜敤錛屽叾浠栧鍣ㄥ垯涓嶉傜敤錛?br />2> capacity鍒欏憡璇変綘鏈灝戞坊鍔犲灝戝厓绱犳墠浼?xì)瀵艰嚧瀹瑰櫒閲嶅垎閰嶅唴瀛樸傝宺eserve鍦ㄥ繀瑕佹椂鎬繪槸浣垮鍣ㄧ殑鍐呭瓨緙撳啿鍖烘墿鑷充竴涓洿澶х殑瀹歸噺銆備粎瀵箆ector鏈夌敤銆?br />3> 浣嗘垜浠疄闄呬笂騫舵湭鍚憊涓坊鍔犱換浣曞厓绱狅紝v浠嶇劧涓虹┖錛佹垜浠彧鑳戒嬌鐢╝t()鎴朳]鍘繪敼鍙橀偅浜涚‘瀹炲瓨鍦ㄤ簬瀹瑰櫒涓殑鍏冪礌錛屼笌瀹瑰櫒澶у皬鎭伅鐩稿叧鐨勩?br />鍥犳v[0] = 1; v[1] = 2;鍦ㄦ煇浜涙儏鍐典笅浼?xì)鈥滈『鍒┾濇墽琛岋紝寤鴻鏈濂戒笉瑕佸姝や嬌鐢紝鍙互浣跨敤resize()鍑芥暟鏉ユ浛浠eserve()鍑芥暟銆?br /><br />浠g爜錛?br /></font> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">1</span> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff">for</span> <span style="COLOR: #000000">聽(vector</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">></span> <span style="COLOR: #000000">::iterator聽i聽</span> <span style="COLOR: #000000">=</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽v.begin();聽<br /></span> <span style="COLOR: #008080">2</span> <span style="COLOR: #000000"> <img id="Codehighlighter1_68_94_Open_Image" onclick="this.style.display='none'; Codehighlighter1_68_94_Open_Text.style.display='none'; Codehighlighter1_68_94_Closed_Image.style.display='inline'; Codehighlighter1_68_94_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />聽聽聽聽聽聽聽i聽</span> <span style="COLOR: #000000"><</span> <span style="COLOR: #000000">聽v.end();聽i</span> <span style="COLOR: #000000">++</span> <span style="COLOR: #000000">)聽</span> <span id="Codehighlighter1_68_94_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"> </span> </font> </font> <span id="Codehighlighter1_68_94_Open_Text"> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">{<br /></span> <span style="COLOR: #008080">3</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />聽聽聽聽cout聽</span> <span style="COLOR: #000000"><<</span> <span style="COLOR: #000000">聽</span> <span style="COLOR: #000000">*</span> <span style="COLOR: #000000">i聽</span> <span style="COLOR: #000000"><<</span> </font> </font> <font face="Courier New"> <font size="2"> <span style="COLOR: #000000">聽endl;<br /></span> <span style="COLOR: #008080">4</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span> </font> </font> </span> <span style="COLOR: #000000"> <br /> </span> <font face="Courier New"> <font size="2"> <span style="COLOR: #008080">5</span> <span style="COLOR: #000000"> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> </span> </font> </font> </div> <p> <font face="Courier New" size="2">浠ヤ笂浠g爜鏈夎濡備互涓嬬殑寤鴻錛?br />1> 灝介噺浣跨敤const.鏈慨鏀箆涓殑鍐呭錛屽彲浣跨敤const_iterator;<br />2> 灝介噺浣跨敤!=鑰屼笉鐢?lt;鏉ユ瘮杈冭凱浠e櫒銆?!= 瀵逛換浣曡凱浠e櫒閮芥湁鏁堬紝鑰?lt; 鍙闅忔満璁塊棶榪唬鍣ㄦ湁鏁堛俵ist涓嶆敮鎸?lt;;<br />3> 灝介噺浣跨敤++鍓嶇紑錛岃岄潪鍚庣紑銆傚彲浠ヤ粠++鍓嶅悗緙鐨勫疄鐜頒唬鐮佷腑寰楃煡錛岄櫎闈炰竴浜涚壒孌婂満鍚堬紱<br />4> 閬垮厤鏃犺皳鐨勯噸澶嶆眰鍊箋倂.end()鍑芥暟鍦ㄩ噸澶嶆眰鍊鹼紝鑰屾暣涓驚鐜湡闂撮兘鏈敼鍙樸傞櫎闈瀍nd()琚紪璇戝櫒榪涜鍐呰仈錛屾棤璋冪敤寮閿錛屾渶濂芥槸灝嗗叾鎻愬埌寰幆澶栭潰錛?br />5> 灝介噺浣跨敤'\n'鑰岄潪endl銆傚師鍥犲湪浜巈ndl浼?xì)杩娇杈撳嚭娴佸堜h柊鍏跺唴閮ㄧ紦鍐插尯錛屽彲浠ュ湪鏁翠釜寰幆涔嬪悗鍐欎竴涓埛鏂拌鍙ャ?br />6> 灝介噺浣跨敤鏍囧噯搴撲腑綆楁硶. 濡俢opy()銆乫or_each()銆備緥濡傝繖閲屽氨鍙互榪欐牱鍐欙細(xì)<br />copy(v.begin(), v.end(), ostream_iterator<int>(cout, '\n'));<br />榪欐牱涓鏉ヤ篃閬垮厤浜?>聽~ 5鐨勯夯鐑?chǔ)銆?br /></font> </p> <p> <font face="Courier New" size="2">// zero</font> </p> <img src ="http://www.shnenglu.com/zerolee/aggbug/13671.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zerolee/" target="_blank">浠勬礇</a> 2006-10-14 15:05 <a href="http://www.shnenglu.com/zerolee/archive/2006/10/14/13671.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>淇偧鎴怌++楂樻墜蹇呯湅鐨凜++涔﹀崟http://www.shnenglu.com/zerolee/archive/2006/09/12/12335.html浠勬礇浠勬礇Tue, 12 Sep 2006 05:11:00 GMThttp://www.shnenglu.com/zerolee/archive/2006/09/12/12335.htmlhttp://www.shnenglu.com/zerolee/comments/12335.htmlhttp://www.shnenglu.com/zerolee/archive/2006/09/12/12335.html#Feedback0http://www.shnenglu.com/zerolee/comments/commentRss/12335.htmlhttp://www.shnenglu.com/zerolee/services/trackbacks/12335.html 澧炴坊浜庣綉涓婄殑涓浜涗功鍗曪細(xì)
C++/OPP/OOD緋誨垪:
灞傜駭涓錛氳娉?璇剰(C++)
[Lippman2000] Essential C++
Essential C++,by Stanley B. Lippman Addison Wesley Longman 2000,276 pages
Essential C++ 涓枃鐗?錛屼警淇婃澃 璇戯紝282欏德?br />Desc: 榪欐湰涔︽瑕佹х殑浠嬬粛浜?jiǎn)C++鏍稿績(jī)鐨勪笢瑗匡紝浣嗚寰楄緝嫻呮樉錛岄傚悎鍒氬叆闂ㄧ殑浜洪槄璇匯?br />

[Andrew Koeing & Barbara MOO] Accelerated C++
Accelerated c++, Andrew Koeing & Barbara MOO, Addison Wesley, 2000
Desc:聽榪欐湰涔︾浉褰撲笉閿欙紝璁茶В鐨凜++緙栫▼鐨勫疄璺典笢瑗褲備篃鐩稿綋閫傚悎棰勫琺鍥篊++璇硶鐭ヨ瘑鐨勪漢闃呰銆?br />

[Eckel2000] Thinking in C++
Thinking in C++ 2/e Bruce Eckel 2000 1470 pages Prentice Hall
C++ 緙栫▼鎬濇兂錛屽垬瀹楃敯絳?璇戯紝420欏?

[Lippman98] C++Primer
C++ Primer,3rd Editoin,by Stanley Lippman and Josee Lajoie
Addison Wesley Longman,1998 1237 pages
C++ Primer 涓枃鐗堬紝渚繆鏉?璇戯紝1999錛?237欏?

[Struostrup2000] The C++ Programming Language
The C++ Programming Language,Special Editoin,by Bjarne Stroustrup
Addison Wesley Longman,2000,1017 pages

[ANSI C++] C++瑙勬牸涔?1998.9.1 PDF鏍煎紡
ANSI C++ 1996 Draft


灞傜駭浜岋細(xì)涓撳緇忛獙(C++/OOP)
[Meyers96] More Effective C++
More Effective C++, by Scott Meyers,Addison Wesley,1996,318pages
More Effective C++涓枃鐗堬紝渚繆鏉幫紝鍩圭敓 2000. 318欏?

[Meyers98] Effective C++
Effective C++, Second Edition,by Scott Meyers,Addison Wesley Longman,1998.256pages
Effective C++ 2/e 涓枃鐗?渚繆鏉?鍩圭敓 2000.256欏?br />Effective C++, Third Edition, by Scott Meyers, Addison Wesley Longman.

[Sutter99] Exceptional C++
Exceptional C++錛宐y Herb Sutter,Addison Wesley Longman,2000.208pages
Exceptional C++涓枃鐗堬紝渚繆鏉?鍩圭敓 2000.248欏?

[Sutter2001]More Exceptional C++
More Exceptional C++ by Herb Sutter, Addison Wesley Longman, 2001.

[Sutter2004]Exception C++ Style
Exception C++ Style by Herb Sutter, Addison Wesley Longman, 2004.

灞傜駭涓夛細(xì)搴曞眰鏈哄埗(C++ Object Model)
[Ellis90] The Annotated C++ Reference Manual
The Annotated C++ Reference Manual,by Margaret A.Ellis and Bjarne Stroustrup
Addison Wesley Longman,1990,447 pages.

[Lippman96] Inside the C++ Object Model
Inside the C++ Object Model,by Stanley Lippman,Addison Wesley Longman,1996,280pages
娣卞害鎺㈢儲(chǔ)C++鐗╀歡妯″瀷錛屼警淇婃澃 璇?

灞傜駭鍥涳細(xì)璁捐瑙傚康鐨勫鐢?C++/Patterns)
[Gamma95] Design Patterns錛欵lements of Reusable Object Oriented Software,
by Erich Gamma,Richard Helm,Ralph Johnson,and John Vlissides,Addison Wesley,1995.395pages
璁捐妯″紡,鏉庤嫳鍐涚瓑璇?鏈烘宸ヤ笟鍑虹増紺?2000.254欏?

[Alex2001]Modern C++ Design: Generic Programming and Design Patterns Applied
by Andrei Alexandrescu,Addison-Wesley,2001,352Paper


Genericity/STL緋誨垪(涓庡眰綰т簩鍚屾錛?
絎竴涓鐣屾槸浣跨敤STL:
[Josuttis99]:The C++ Standard Library 錛岮 Tutorial and Reference,by Nicolai M.Josuttis,
Addison Wesley 1999.799pages

絎簩涓鐣屾槸浜?jiǎn)瑙f硾鍨嬫妧鏈殑鍐呮兜涓嶴TL鐨勫鐞?
[Austern98]:Generic Programming and the STL -Using and Extending the C++ Standard
Template library,by Matthew H.Austern,Addison Wesley 1998.548page


絎笁涓鐣屾槸鎵╁厖STL:
[Stepanov2001]:C++ Standard Template Library by P.J.Plauger,Alexander A.Stepanov,
Meng Lee,David R.Musser,Prentice Hall 2001

鍏朵粬涔︾洰錛?br />1. Large-scale C++ software Design, John Lako, Addison Wesley, 1996
2. Effective STL, Scott Meyers, Addison Wesley, 1995
3. C++ FAQs, 2nd, Marshall Cline, Greg Lomow, Mike Girou, Addison Wesley, 1998
4. C++ Gotchas, Stephen Dewhurst, Addison Wesley, 2002
5. C++ templates, the complete Guide, Daveed Vandevoorde & Nicolar M.Josuttis, Addison Wesley, 2002
6. Standard C++ iostreams and Locals, Angelika Langer & Klaus Kreft, Addison Wesley, 2000
7. Design & Evolution of C++, BS, Addison Wesley, 1994
8. Modern C++ Design, Andrie Alexandrescu, Addison Wesley, 2001
9. Generative Programming, Krzysztof Czarnecki & Ulrich Eisencecker, Addison Wesley, 2000
10.Pattern-oriented software architecture, Vol1:A system of patterns, Frank Buschmann, 1996
11. STL 婧愮爜鍓栨瀽錛屼警鏉?br />12. C++ Coding Standards 101 Rules Guidelines, Andrie Alexandrescu & Herb Sutter, Addison Wesley, 2005



浠勬礇 2006-09-12 13:11 鍙戣〃璇勮
]]>
2021少妇久久久久久久久久| 久久久久中文字幕| 中文字幕日本人妻久久久免费| 欧美粉嫩小泬久久久久久久| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 精品综合久久久久久97| 久久久精品人妻一区二区三区蜜桃| 狠狠色丁香婷婷久久综合 | 99久久成人18免费网站| 精品久久久久久国产三级| 久久天天躁狠狠躁夜夜av浪潮| 日韩久久无码免费毛片软件| 色老头网站久久网| 人妻无码αv中文字幕久久琪琪布| 色妞色综合久久夜夜| 精品久久一区二区三区| 久久久WWW免费人成精品| 久久久久九九精品影院| 国内精品伊人久久久久777| 久久久久久亚洲精品成人| 99久久免费只有精品国产| 午夜精品久久久内射近拍高清| 一本久久a久久精品vr综合| 77777亚洲午夜久久多喷| 久久99精品免费一区二区| 国产免费久久精品99re丫y| 久久精品亚洲精品国产色婷| 93精91精品国产综合久久香蕉| 亚洲精品国产综合久久一线| 久久精品中文字幕无码绿巨人| 亚洲伊人久久大香线蕉苏妲己| 久久大香萑太香蕉av| 久久精品男人影院| 伊人久久精品影院| 99久久婷婷免费国产综合精品| 日韩十八禁一区二区久久| 久久超碰97人人做人人爱| 久久精品国产亚洲5555| 久久综合88熟人妻| 亚洲国产精品嫩草影院久久| 久久96国产精品久久久|