﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-foobar</title><link>http://www.cppblog.com/foobar/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 14 Apr 2026 23:06:06 GMT</lastBuildDate><pubDate>Tue, 14 Apr 2026 23:06:06 GMT</pubDate><ttl>60</ttl><item><title>Advanced Test in C: The 0x10 Best Questions for C Programmers </title><link>http://www.cppblog.com/foobar/archive/2007/12/03/37683.html</link><dc:creator>foobar</dc:creator><author>foobar</author><pubDate>Mon, 03 Dec 2007 07:12:00 GMT</pubDate><guid>http://www.cppblog.com/foobar/archive/2007/12/03/37683.html</guid><wfw:comment>http://www.cppblog.com/foobar/comments/37683.html</wfw:comment><comments>http://www.cppblog.com/foobar/archive/2007/12/03/37683.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foobar/comments/commentRss/37683.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foobar/services/trackbacks/37683.html</trackback:ping><description><![CDATA[<a href="http://www.programmersheaven.com/articles/pathak/article2.htm" target=_blank>Advanced Test in C: The 0x10 Best Questions for C Programmers </a><br>
<img src ="http://www.cppblog.com/foobar/aggbug/37683.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foobar/" target="_blank">foobar</a> 2007-12-03 15:12 <a href="http://www.cppblog.com/foobar/archive/2007/12/03/37683.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>隐藏</title><link>http://www.cppblog.com/foobar/archive/2007/11/23/37221.html</link><dc:creator>foobar</dc:creator><author>foobar</author><pubDate>Fri, 23 Nov 2007 12:44:00 GMT</pubDate><guid>http://www.cppblog.com/foobar/archive/2007/11/23/37221.html</guid><wfw:comment>http://www.cppblog.com/foobar/comments/37221.html</wfw:comment><comments>http://www.cppblog.com/foobar/archive/2007/11/23/37221.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foobar/comments/commentRss/37221.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foobar/services/trackbacks/37221.html</trackback:ping><description><![CDATA[<p>&nbsp;</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: #000000">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Base<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br></span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;f(</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">&nbsp;x){&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Base::f(float)&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl;&nbsp;}<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;g(</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">&nbsp;x){&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Base::g(float)&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl;&nbsp;}<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;h(</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">&nbsp;x){&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Base::h(float)&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl;&nbsp;}<br>};<br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Derived&nbsp;:&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;Base<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br></span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;f(</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">&nbsp;x){&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Derived::f(float)&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl;&nbsp;}<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;g(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x){&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Derived::g(int)&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl;&nbsp;}<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;h(</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">&nbsp;x){&nbsp;cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Derived::h(float)&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl;&nbsp;}<br>};<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;main(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br>{<br>Derived&nbsp;d;<br>Base&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pb&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">d;<br>Derived&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pd&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">d;<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Good&nbsp;:&nbsp;behavior&nbsp;depends&nbsp;solely&nbsp;on&nbsp;type&nbsp;of&nbsp;the&nbsp;object</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">pb</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">f(</span><span style="COLOR: #000000">3.14f</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Derived::f(float)&nbsp;3.14</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">pd</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">f(</span><span style="COLOR: #000000">3.14f</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Derived::f(float)&nbsp;3.14<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Bad&nbsp;:&nbsp;behavior&nbsp;depends&nbsp;on&nbsp;type&nbsp;of&nbsp;the&nbsp;pointer</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">pb</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">g(</span><span style="COLOR: #000000">3.14f</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Base::g(float)&nbsp;3.14</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">pd</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">g(</span><span style="COLOR: #000000">3.14f</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Derived::g(int)&nbsp;3&nbsp;(surprise!)<br></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Bad&nbsp;:&nbsp;behavior&nbsp;depends&nbsp;on&nbsp;type&nbsp;of&nbsp;the&nbsp;pointer</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">pb</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">h(</span><span style="COLOR: #000000">3.14f</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Base::h(float)&nbsp;3.14&nbsp;(surprise!)</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">pd</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">h(</span><span style="COLOR: #000000">3.14f</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Derived::h(float)&nbsp;3.14</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">}<br></span></div>
<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: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Base<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;f(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x);<br>};<br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;Derived&nbsp;:&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">&nbsp;Base<br>{<br></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;f(</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">str);<br>};<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;Test(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br>{<br>Derived&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pd&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000">&nbsp;Derived;<br>pd</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">f(</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;error<br>//why?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: #008000">just imagine multiple inheritance<br></span><span style="COLOR: #000000">}</span></div>
<img src ="http://www.cppblog.com/foobar/aggbug/37221.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foobar/" target="_blank">foobar</a> 2007-11-23 20:44 <a href="http://www.cppblog.com/foobar/archive/2007/11/23/37221.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>隐式类型转换导致重载函数产生二义性</title><link>http://www.cppblog.com/foobar/archive/2007/11/23/37220.html</link><dc:creator>foobar</dc:creator><author>foobar</author><pubDate>Fri, 23 Nov 2007 12:35:00 GMT</pubDate><guid>http://www.cppblog.com/foobar/archive/2007/11/23/37220.html</guid><wfw:comment>http://www.cppblog.com/foobar/comments/37220.html</wfw:comment><comments>http://www.cppblog.com/foobar/archive/2007/11/23/37220.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foobar/comments/commentRss/37220.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foobar/services/trackbacks/37220.html</trackback:ping><description><![CDATA[<p>&nbsp;</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">&nbsp;1</span>&nbsp;<span style="COLOR: #000000">#&nbsp;include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;output(&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;函数声明</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;3</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;output(&nbsp;</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">&nbsp;x);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;函数声明</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;4</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;output(&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x)<br></span><span style="COLOR: #008080">&nbsp;5</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;6</span>&nbsp;<span style="COLOR: #000000">cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;output&nbsp;int&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl&nbsp;;<br></span><span style="COLOR: #008080">&nbsp;7</span>&nbsp;<span style="COLOR: #000000">}<br></span><span style="COLOR: #008080">&nbsp;8</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;output(&nbsp;</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">&nbsp;x)<br></span><span style="COLOR: #008080">&nbsp;9</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">10</span>&nbsp;<span style="COLOR: #000000">cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;output&nbsp;float&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;endl&nbsp;;<br></span><span style="COLOR: #008080">11</span>&nbsp;<span style="COLOR: #000000">}<br></span><span style="COLOR: #008080">12</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;main(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">13</span>&nbsp;<span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">14</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;x&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">15</span>&nbsp;<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">&nbsp;y&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1.0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">16</span>&nbsp;<span style="COLOR: #000000">output(x);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;output&nbsp;int&nbsp;1</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">17</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #000000">output(y);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;output&nbsp;float&nbsp;1</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">18</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #000000">output(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;output&nbsp;int&nbsp;1<br></span><span style="COLOR: #008080">19</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;output(0.5);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;error!&nbsp;ambiguous&nbsp;call,&nbsp;因为自动类型转换</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">20</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #000000">output(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0.5</span><span style="COLOR: #000000">));&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;output&nbsp;int&nbsp;0</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">21</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #000000">output(</span><span style="COLOR: #0000ff">float</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">0.5</span><span style="COLOR: #000000">));&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;output&nbsp;float&nbsp;0.5</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">22</span>&nbsp;<span style="COLOR: #008000"></span><span style="COLOR: #000000">}</span></div>
<img src ="http://www.cppblog.com/foobar/aggbug/37220.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foobar/" target="_blank">foobar</a> 2007-11-23 20:35 <a href="http://www.cppblog.com/foobar/archive/2007/11/23/37220.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数组退化为指针</title><link>http://www.cppblog.com/foobar/archive/2007/11/23/37218.html</link><dc:creator>foobar</dc:creator><author>foobar</author><pubDate>Fri, 23 Nov 2007 12:22:00 GMT</pubDate><guid>http://www.cppblog.com/foobar/archive/2007/11/23/37218.html</guid><wfw:comment>http://www.cppblog.com/foobar/comments/37218.html</wfw:comment><comments>http://www.cppblog.com/foobar/archive/2007/11/23/37218.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foobar/comments/commentRss/37218.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foobar/services/trackbacks/37218.html</trackback:ping><description><![CDATA[void Func(char a[100])<br>{<br>cout&lt;&lt; sizeof(a) &lt;&lt; endl; // 4 字节而不是100 字节<br>}
<img src ="http://www.cppblog.com/foobar/aggbug/37218.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foobar/" target="_blank">foobar</a> 2007-11-23 20:22 <a href="http://www.cppblog.com/foobar/archive/2007/11/23/37218.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>atexit   --       function to be executed on exit</title><link>http://www.cppblog.com/foobar/archive/2007/11/15/36729.html</link><dc:creator>foobar</dc:creator><author>foobar</author><pubDate>Thu, 15 Nov 2007 15:47:00 GMT</pubDate><guid>http://www.cppblog.com/foobar/archive/2007/11/15/36729.html</guid><wfw:comment>http://www.cppblog.com/foobar/comments/36729.html</wfw:comment><comments>http://www.cppblog.com/foobar/archive/2007/11/15/36729.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foobar/comments/commentRss/36729.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foobar/services/trackbacks/36729.html</trackback:ping><description><![CDATA[<font color=#008000>
<pre>int atexit ( void ( * function ) (void) );               </font><font color=#000080>&lt;cstdlib&gt;</pre>
<p><strong></strong>&nbsp;The function pointed by the <em>function</em> pointer argument is called when the program terminates normally. </p>
<p>If more than one <tt>atexit</tt> function has been specified by different calls to this function, they are all executed in reverse order as a stack, i.e. the last function specified is the first to be executed at exit.
<p>One single function can be registered to be executed at exit more than once.
<p>C++ implementations are required to support the registration of at least 32 <tt>atexit</tt> functions.
<p>
<h3>Parameters</h3>
<dl>
<dt>function
<dd>Function to be called. The function has to return no value and accept no arguments. </dd></dl>
<p>
<h3>Return Value</h3>
A zero value is returned if the function was successfully registered, or a non-zero value if it failed.
<p>
<h3>Example</h3>
<table class=snippet>
    <tbody>
        <tr>
            <td class=code>
            <pre><span class=comm><font color=#007000>/* atexit example */</font></span>
            <span class=prep><font color=#500070>#include &lt;stdio.h&gt;</font></span>
            <span class=prep><font color=#500070>#include &lt;stdlib.h&gt;</font></span>
            <span class=kw><font color=#0000b0>void</font></span> fnExit1 (<span class=kw><font color=#0000b0>void</font></span>)
            {
            puts (<span class=str><font color=#600030>"Exit function 1."</font></span>);
            }
            <span class=kw><font color=#0000b0>void</font></span> fnExit2 (<span class=kw><font color=#0000b0>void</font></span>)
            {
            puts (<span class=str><font color=#600030>"Exit function 2."</font></span>);
            }
            <span class=kw><font color=#0000b0>int</font></span> main ()
            {
            atexit (fnExit1);
            atexit (fnExit2);
            puts (<span class=str><font color=#600030>"Main function."</font></span>);
            <span class=kw><font color=#0000b0>return</font></span> 0;
            }
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<p>Output:<br>
<table class=snippet>
    <tbody>
        <tr>
            <td class=result>
            <pre><tt>
            Main function.<br>Exit function 2.<br>Exit function 1.<br></tt></pre>
            </td>
        </tr>
    </tbody>
</table>
</p>
</font>
<img src ="http://www.cppblog.com/foobar/aggbug/36729.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foobar/" target="_blank">foobar</a> 2007-11-15 23:47 <a href="http://www.cppblog.com/foobar/archive/2007/11/15/36729.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Gotchas in the C++ programing language</title><link>http://www.cppblog.com/foobar/archive/2007/06/04/25442.html</link><dc:creator>foobar</dc:creator><author>foobar</author><pubDate>Mon, 04 Jun 2007 03:11:00 GMT</pubDate><guid>http://www.cppblog.com/foobar/archive/2007/06/04/25442.html</guid><wfw:comment>http://www.cppblog.com/foobar/comments/25442.html</wfw:comment><comments>http://www.cppblog.com/foobar/archive/2007/06/04/25442.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/foobar/comments/commentRss/25442.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/foobar/services/trackbacks/25442.html</trackback:ping><description><![CDATA[<h3><span class=mw-headline>Initializer lists</span></h3>
<p>In C++, it is the order of the class inheritance and of the member variables that determine the initialization order, <em>not</em> the order of an initializer list:<br></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"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;CSomeClass<br><img id=Codehighlighter1_40_152_Open_Image onclick="this.style.display='none'; Codehighlighter1_40_152_Open_Text.style.display='none'; Codehighlighter1_40_152_Closed_Image.style.display='inline'; Codehighlighter1_40_152_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_40_152_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_40_152_Closed_Text.style.display='none'; Codehighlighter1_40_152_Open_Image.style.display='inline'; Codehighlighter1_40_152_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_40_152_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_40_152_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>CSomeClass(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;n)<br><img id=Codehighlighter1_68_150_Open_Image onclick="this.style.display='none'; Codehighlighter1_68_150_Open_Text.style.display='none'; Codehighlighter1_68_150_Closed_Image.style.display='inline'; Codehighlighter1_68_150_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_68_150_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_68_150_Closed_Text.style.display='none'; Codehighlighter1_68_150_Open_Image.style.display='inline'; Codehighlighter1_68_150_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top></span><span id=Codehighlighter1_68_150_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_68_150_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>std::cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">CSomeClass&nbsp;constructor&nbsp;with&nbsp;value&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>std::cout&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;n&nbsp;</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">&nbsp;std::endl;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;CSomeOtherClass<br><img id=Codehighlighter1_178_369_Open_Image onclick="this.style.display='none'; Codehighlighter1_178_369_Open_Text.style.display='none'; Codehighlighter1_178_369_Closed_Image.style.display='inline'; Codehighlighter1_178_369_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_178_369_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_178_369_Closed_Text.style.display='none'; Codehighlighter1_178_369_Open_Image.style.display='inline'; Codehighlighter1_178_369_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_178_369_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_178_369_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>CSomeOtherClass()&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">In&nbsp;this&nbsp;example,&nbsp;despite&nbsp;the&nbsp;list&nbsp;order,</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">:&nbsp;obj2(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">),&nbsp;obj1(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">obj1&nbsp;will&nbsp;be&nbsp;initialized&nbsp;before&nbsp;obj2.</span><span style="COLOR: #008000"><br><img id=Codehighlighter1_308_324_Open_Image onclick="this.style.display='none'; Codehighlighter1_308_324_Open_Text.style.display='none'; Codehighlighter1_308_324_Closed_Image.style.display='inline'; Codehighlighter1_308_324_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_308_324_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_308_324_Closed_Text.style.display='none'; Codehighlighter1_308_324_Open_Image.style.display='inline'; Codehighlighter1_308_324_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top></span><span id=Codehighlighter1_308_324_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_308_324_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Do&nbsp;nothing.</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>CSomeClass&nbsp;obj1;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>CSomeClass&nbsp;obj2;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_388_421_Open_Image onclick="this.style.display='none'; Codehighlighter1_388_421_Open_Text.style.display='none'; Codehighlighter1_388_421_Closed_Image.style.display='inline'; Codehighlighter1_388_421_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_388_421_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_388_421_Closed_Text.style.display='none'; Codehighlighter1_388_421_Open_Image.style.display='inline'; Codehighlighter1_388_421_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_388_421_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_388_421_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>CSomeOtherClass&nbsp;obj;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/foobar/aggbug/25442.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/foobar/" target="_blank">foobar</a> 2007-06-04 11:11 <a href="http://www.cppblog.com/foobar/archive/2007/06/04/25442.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>