﻿<?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++博客-小山日志</title><link>http://www.cppblog.com/nj-blog/</link><description>读书,学习与思考.</description><language>zh-cn</language><lastBuildDate>Thu, 23 Apr 2026 04:12:05 GMT</lastBuildDate><pubDate>Thu, 23 Apr 2026 04:12:05 GMT</pubDate><ttl>60</ttl><item><title>绘制牛顿法复杂边界分形图 &amp;&amp; 海皮扭耶！</title><link>http://www.cppblog.com/nj-blog/archive/2006/12/31/17108.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Sun, 31 Dec 2006 15:58:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/12/31/17108.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/17108.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/12/31/17108.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/17108.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/17108.html</trackback:ping><description><![CDATA[
		<p>
				<img src="http://www.cppblog.com/images/cppblog_com/nj-blog/2767/r_fenxing.PNG" />
				<br />谨以此图BS自己的懒惰行为！呵呵，3月份的想法到现在才完成。还好没有拖到07年去^_^。<br />先把图片和代码给出，明天再把文字补上。<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 id="Code_Closed_Image" onclick="this.style.display='none'; Code_Closed_Text.style.display='none'; Code_Open_Image.style.display='inline'; Code_Open_Text.style.display='inline';" height="16" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" />
				<img id="Code_Open_Image" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text.style.display='none'; Code_Closed_Image.style.display='inline'; Code_Closed_Text.style.display='inline';" height="16" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" />
				<span id="Code_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
				</span>
				<span id="Code_Open_Text" style="DISPLAY: none">
						<br />
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> 在VC7.1和Dev C++下编译通过</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						</span>
						<span style="COLOR: #000000">#include </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">windows.h</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">cstring</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">complex</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">iostream</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">fstream</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						</span>
						<span style="COLOR: #0000ff">using</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">namespace</span>
						<span style="COLOR: #000000"> std;<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: #008000">//</span>
						<span style="COLOR: #008000">设置迭代次数。。。</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						</span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> unsigned </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> MAX </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">  </span>
						<span style="COLOR: #000000">100</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: #008000">//</span>
						<span style="COLOR: #008000">设置图片像素，默认取图片大小为 800×600</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						</span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> setPixel(LPBYTE lpBits, unsigned </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> x, unsigned </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> y, BYTE r, BYTE g, BYTE b)<br /><img id="Codehighlighter1_298_389_Open_Image" onclick="this.style.display='none'; Codehighlighter1_298_389_Open_Text.style.display='none'; Codehighlighter1_298_389_Closed_Image.style.display='inline'; Codehighlighter1_298_389_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_298_389_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_298_389_Closed_Text.style.display='none'; Codehighlighter1_298_389_Open_Image.style.display='inline'; Codehighlighter1_298_389_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
						<span id="Codehighlighter1_298_389_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_298_389_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    lpBits </span>
								<span style="COLOR: #000000">+=</span>
								<span style="COLOR: #000000"> y</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">800</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> x</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">lpBits        </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> b;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">(lpBits</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">) </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> g;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">(lpBits</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">2</span>
								<span style="COLOR: #000000">) </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> r;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #0000ff">return</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: #008000">//</span>
						<span style="COLOR: #008000">指定染色规则</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						</span>
						<span style="COLOR: #000000">template</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">typename T</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_439_461_Open_Image" onclick="this.style.display='none'; Codehighlighter1_439_461_Open_Text.style.display='none'; Codehighlighter1_439_461_Closed_Image.style.display='inline'; Codehighlighter1_439_461_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
								<img id="Codehighlighter1_439_461_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_439_461_Closed_Text.style.display='none'; Codehighlighter1_439_461_Open_Image.style.display='inline'; Codehighlighter1_439_461_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />inline T fun(T k)</span>
						<span id="Codehighlighter1_439_461_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_439_461_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> (k</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">41</span>
								<span style="COLOR: #000000">)</span>
								<span style="COLOR: #000000">%</span>
								<span style="COLOR: #000000">255</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">int</span>
						<span style="COLOR: #000000"> main(</span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> argc, </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">argv[])<br /><img id="Codehighlighter1_497_2362_Open_Image" onclick="this.style.display='none'; Codehighlighter1_497_2362_Open_Text.style.display='none'; Codehighlighter1_497_2362_Closed_Image.style.display='inline'; Codehighlighter1_497_2362_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_497_2362_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_497_2362_Closed_Text.style.display='none'; Codehighlighter1_497_2362_Open_Image.style.display='inline'; Codehighlighter1_497_2362_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
						<span id="Codehighlighter1_497_2362_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_497_2362_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"> 测试complex<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">   complex&lt;double&gt; c1(4.3, 3.0);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">   complex&lt;double&gt; c2=c1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">   <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">   for(int j=0; j&lt; 4800; j++){    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">       for(int i=0; i&lt;100; i++){<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">           c2 = (c1*2.0+1.0/(c1*c1))/3.0;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">           if(c2==c1) break;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">           c1=c2;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">       }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">          c1=complex&lt;double&gt;(4.3, 3.0);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">   }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">      cout &lt;&lt; j &lt;&lt; endl;</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    BITMAPFILEHEADER  hdr;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    BITMAPINFOHEADER  bih;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    LPBYTE  lpBits;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ZeroMemory(</span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">hdr, </span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(hdr));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ZeroMemory(</span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">bih, </span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(bih));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bih.biSize    </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">    </span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(bih);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bih.biWidth    </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">    </span>
								<span style="COLOR: #000000">800</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bih.biHeight</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">    </span>
								<span style="COLOR: #000000">600</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bih.biPlanes</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">   </span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bih.biCompression </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> BI_RGB;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bih.biBitCount    </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">24</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    bih.biSizeImage </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    hdr.bfType </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0x4d42</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    hdr.bfSize </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> (DWORD) (</span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(BITMAPFILEHEADER) </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        bih.biSize </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">800</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">600</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    hdr.bfOffBits </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> (DWORD)(</span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(BITMAPFILEHEADER) </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        bih.biSize);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    lpBits </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> unsigned </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000">[</span>
								<span style="COLOR: #000000">800</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">600</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">];<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    memset(lpBits, </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">, </span>
								<span style="COLOR: #000000">800</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">600</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">测试图片写入<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">for(int j=0; j&lt; 600/2; j++)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">    for (int i=0; i&lt;800; i++)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">    {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">        setPixel(lpBits, i, j, 250, 0, 0);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">    }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">}</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    complex</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #0000ff">double</span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000"> c2,c1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> i,j, k;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000">(j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">600</span>
								<span style="COLOR: #000000">; j</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_1565_2042_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1565_2042_Open_Text.style.display='none'; Codehighlighter1_1565_2042_Closed_Image.style.display='inline'; Codehighlighter1_1565_2042_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1565_2042_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1565_2042_Closed_Text.style.display='none'; Codehighlighter1_1565_2042_Open_Image.style.display='inline'; Codehighlighter1_1565_2042_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
								<span id="Codehighlighter1_1565_2042_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_1565_2042_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">for</span>
										<span style="COLOR: #000000">(i</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">; i</span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000">800</span>
										<span style="COLOR: #000000">; i</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_1592_2039_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1592_2039_Open_Text.style.display='none'; Codehighlighter1_1592_2039_Closed_Image.style.display='inline'; Codehighlighter1_1592_2039_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1592_2039_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1592_2039_Closed_Text.style.display='none'; Codehighlighter1_1592_2039_Open_Image.style.display='inline'; Codehighlighter1_1592_2039_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
										<span id="Codehighlighter1_1592_2039_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_1592_2039_Open_Text">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            c1 </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> complex</span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #0000ff">double</span>
												<span style="COLOR: #000000">&gt;</span>
												<span style="COLOR: #000000">(i</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">0.01</span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">4</span>
												<span style="COLOR: #000000">, j</span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">0.01</span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">3</span>
												<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">迭代个点</span>
												<span style="COLOR: #008000">
														<br />
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
												</span>
												<span style="COLOR: #000000">            </span>
												<span style="COLOR: #0000ff">for</span>
												<span style="COLOR: #000000">(k</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">; k</span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000">MAX; k</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_1676_1749_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1676_1749_Open_Text.style.display='none'; Codehighlighter1_1676_1749_Closed_Image.style.display='inline'; Codehighlighter1_1676_1749_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1676_1749_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1676_1749_Closed_Text.style.display='none'; Codehighlighter1_1676_1749_Open_Image.style.display='inline'; Codehighlighter1_1676_1749_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
												<span id="Codehighlighter1_1676_1749_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_1676_1749_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                c2 </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> (c1</span>
														<span style="COLOR: #000000">*</span>
														<span style="COLOR: #000000">2.0</span>
														<span style="COLOR: #000000">+</span>
														<span style="COLOR: #000000">1.0</span>
														<span style="COLOR: #000000">/</span>
														<span style="COLOR: #000000">(c1</span>
														<span style="COLOR: #000000">*</span>
														<span style="COLOR: #000000">c1))</span>
														<span style="COLOR: #000000">/</span>
														<span style="COLOR: #000000">3.0</span>
														<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000">(c2</span>
														<span style="COLOR: #000000">==</span>
														<span style="COLOR: #000000">c1) </span>
														<span style="COLOR: #0000ff">break</span>
														<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                c1</span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000">c2;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<img id="Codehighlighter1_1764_1806_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1764_1806_Open_Text.style.display='none'; Codehighlighter1_1764_1806_Closed_Image.style.display='inline'; Codehighlighter1_1764_1806_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
														<img id="Codehighlighter1_1764_1806_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1764_1806_Closed_Text.style.display='none'; Codehighlighter1_1764_1806_Open_Image.style.display='inline'; Codehighlighter1_1764_1806_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000">(k</span>
												<span style="COLOR: #000000">==</span>
												<span style="COLOR: #000000">MAX)</span>
												<span id="Codehighlighter1_1764_1806_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_1764_1806_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                setPixel(lpBits, i, j, </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">, </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">, </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">);<br /><img id="Codehighlighter1_1847_1894_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1847_1894_Open_Text.style.display='none'; Codehighlighter1_1847_1894_Closed_Image.style.display='inline'; Codehighlighter1_1847_1894_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1847_1894_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1847_1894_Closed_Text.style.display='none'; Codehighlighter1_1847_1894_Open_Image.style.display='inline'; Codehighlighter1_1847_1894_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            }</span>
												</span>
												<span style="COLOR: #0000ff">else</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000">( c1.real() </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">&amp;&amp;</span>
												<span style="COLOR: #000000"> c1.imag() </span>
												<span style="COLOR: #000000">&gt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">)</span>
												<span id="Codehighlighter1_1847_1894_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_1847_1894_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                setPixel(lpBits, i, j, fun(k), </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">, </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">);<br /><img id="Codehighlighter1_1935_1982_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1935_1982_Open_Text.style.display='none'; Codehighlighter1_1935_1982_Closed_Image.style.display='inline'; Codehighlighter1_1935_1982_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1935_1982_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1935_1982_Closed_Text.style.display='none'; Codehighlighter1_1935_1982_Open_Image.style.display='inline'; Codehighlighter1_1935_1982_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            }</span>
												</span>
												<span style="COLOR: #0000ff">else</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000">( c1.real() </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">&amp;&amp;</span>
												<span style="COLOR: #000000"> c1.imag() </span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">)</span>
												<span id="Codehighlighter1_1935_1982_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_1935_1982_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                setPixel(lpBits, i, j, </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">, fun(k), </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">);<br /><img id="Codehighlighter1_1987_2034_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1987_2034_Open_Text.style.display='none'; Codehighlighter1_1987_2034_Closed_Image.style.display='inline'; Codehighlighter1_1987_2034_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1987_2034_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1987_2034_Closed_Text.style.display='none'; Codehighlighter1_1987_2034_Open_Image.style.display='inline'; Codehighlighter1_1987_2034_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            }</span>
												</span>
												<span style="COLOR: #0000ff">else</span>
												<span id="Codehighlighter1_1987_2034_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_1987_2034_Open_Text">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                setPixel(lpBits, i, j, </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">, </span>
														<span style="COLOR: #000000">0</span>
														<span style="COLOR: #000000">, fun(k));<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/InBlock.gif" align="top" />
														<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/ExpandedSubBlockEnd.gif" align="top" />    }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">写入文件</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">    ofstream  file(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">fenxing.bmp</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000"> pTmp </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> reinterpret_cast</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000">*&gt;</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">hdr);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    file.write(pTmp, </span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(BITMAPFILEHEADER));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    pTmp </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> reinterpret_cast</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000">*&gt;</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">&amp;</span>
								<span style="COLOR: #000000">bih);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    file.write(pTmp, </span>
								<span style="COLOR: #0000ff">sizeof</span>
								<span style="COLOR: #000000">(BITMAPINFOHEADER));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    file.write(reinterpret_cast</span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000">*&gt;</span>
								<span style="COLOR: #000000">(lpBits), </span>
								<span style="COLOR: #000000">800</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">600</span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">3</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    delete []lpBits;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> EXIT_SUCCESS;<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>
				</span>
		</div>
		<p>
				<br />
		</p>
<img src ="http://www.cppblog.com/nj-blog/aggbug/17108.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-12-31 23:58 <a href="http://www.cppblog.com/nj-blog/archive/2006/12/31/17108.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>纯C编写的矩阵工具包</title><link>http://www.cppblog.com/nj-blog/archive/2006/12/07/16099.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Thu, 07 Dec 2006 09:06:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/12/07/16099.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/16099.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/12/07/16099.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/16099.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/16099.html</trackback:ping><description><![CDATA[同学找我帮忙写的，要求：<br />矩阵相乘，纯C编写。<br />不能用C++这点让我十分郁闷啊^_^....<br />一共包含如下东西：<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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">typedef </span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000"> _matrix2D matrix2D; </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">一个结构体类型matrix2D</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />BOOL initMatrix(matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pm, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> h, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> w); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">初始化pm为h×w的零矩阵</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> delMatrix(matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pm);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">矩阵的内部数据空间全部是动态分配的，所以退出之前一定要删除矩阵</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> getData(matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pm, </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">返回矩阵pm，坐标为x、y的元素值</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setData(matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pm, </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: #0000ff">int</span><span style="COLOR: #000000"> data);   </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">将矩阵pm，坐标为x、y的元素值置为data</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setMatrix(matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> lhs, matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> rhs);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">删除矩阵lhs原先的值，并深层拷贝为rhs</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">matrix2D addMatrix(matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> lhs, matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> rhs);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">矩阵相加，返回一个新的矩阵</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">matrix2D mulMatrix(matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> lhs, matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> rhs);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">矩阵相乘，返回一个新的矩阵</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> printMatrix(matrix2D</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pm);  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">格式化打印矩阵pm</span></div><br />这是一个测试程序，简单相乘两个矩阵：<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"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">matrix2d.h</span><span style="COLOR: #000000">"</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"> main()<br /><img id="Codehighlighter1_34_664_Open_Image" onclick="this.style.display='none'; Codehighlighter1_34_664_Open_Text.style.display='none'; Codehighlighter1_34_664_Closed_Image.style.display='inline'; Codehighlighter1_34_664_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_34_664_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_34_664_Closed_Text.style.display='none'; Codehighlighter1_34_664_Open_Image.style.display='inline'; Codehighlighter1_34_664_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_34_664_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_34_664_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i,j;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    matrix2D  rhs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    matrix2D  lhs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    matrix2D  result;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    initMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">lhs, </span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    initMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">rhs, </span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">lhs矩阵设置元素值</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_216_299_Open_Image" onclick="this.style.display='none'; Codehighlighter1_216_299_Open_Text.style.display='none'; Codehighlighter1_216_299_Closed_Image.style.display='inline'; Codehighlighter1_216_299_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_216_299_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_216_299_Closed_Text.style.display='none'; Codehighlighter1_216_299_Open_Image.style.display='inline'; Codehighlighter1_216_299_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_216_299_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_216_299_Open_Text"><span style="COLOR: #000000">{<br /><img id="Codehighlighter1_247_293_Open_Image" onclick="this.style.display='none'; Codehighlighter1_247_293_Open_Text.style.display='none'; Codehighlighter1_247_293_Closed_Image.style.display='inline'; Codehighlighter1_247_293_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_247_293_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_247_293_Closed_Text.style.display='none'; Codehighlighter1_247_293_Open_Image.style.display='inline'; Codehighlighter1_247_293_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_247_293_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_247_293_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            setData(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">lhs, i, j, </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<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/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><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">rhs矩阵设置元素值</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_347_431_Open_Image" onclick="this.style.display='none'; Codehighlighter1_347_431_Open_Text.style.display='none'; Codehighlighter1_347_431_Closed_Image.style.display='inline'; Codehighlighter1_347_431_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_347_431_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_347_431_Closed_Text.style.display='none'; Codehighlighter1_347_431_Open_Image.style.display='inline'; Codehighlighter1_347_431_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_347_431_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_347_431_Open_Text"><span style="COLOR: #000000">{<br /><img id="Codehighlighter1_377_425_Open_Image" onclick="this.style.display='none'; Codehighlighter1_377_425_Open_Text.style.display='none'; Codehighlighter1_377_425_Closed_Image.style.display='inline'; Codehighlighter1_377_425_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_377_425_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_377_425_Closed_Text.style.display='none'; Codehighlighter1_377_425_Open_Image.style.display='inline'; Codehighlighter1_377_425_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)</span><span id="Codehighlighter1_377_425_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_377_425_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            setData(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">rhs, i, j, i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<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/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><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">矩阵相乘</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">    result </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> mulMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">lhs, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">rhs);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">打印三个矩阵</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">    printMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">lhs);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">rhs);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    printMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">result);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">不用了，记得释放矩阵空间..</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">    delMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">lhs);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    delMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">rhs);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    delMatrix(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">result);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div><br />这里是显示结果：<br /><a class="" title="" href="/images/cppblog_com/nj-blog/2767/r_martin.JPG" target=""><img style="WIDTH: 73px; HEIGHT: 120px" height="120" src="http://www.cppblog.com/images/cppblog_com/nj-blog/2767/t_martin.JPG" width="188" /></a><br />点击<a class="" title="" href="/Files/nj-blog/matrix.rar" target="">这里</a>下载完整的源代码和运行程序。<br /><img src ="http://www.cppblog.com/nj-blog/aggbug/16099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-12-07 17:06 <a href="http://www.cppblog.com/nj-blog/archive/2006/12/07/16099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>将逆波兰式转换成波兰式表达式</title><link>http://www.cppblog.com/nj-blog/archive/2006/12/05/16011.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Tue, 05 Dec 2006 06:45:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/12/05/16011.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/16011.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/12/05/16011.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/16011.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/16011.html</trackback:ping><description><![CDATA[    这是严蔚敏《数据结构》配套习题册上的题目：将逆波兰式转换成波兰式，并提示错误（作为简化，只处理"+-*/"和0~9的数字）。<br />    例如："123*-"转换成波兰式为"-1*23"<br />    逆波兰式"123*-"的表达式树如下：<br />    <img title="exp-tree" style="width: 206px; height: 166px;" src="http://docs.google.com/File?id=dddhs32p_4cztm4q" />所以这个转换过程就是：已知一个二叉树的后根遍历序列，求先根遍历序列。<br />    我的算法是根据后根遍历的序列构造一个表达式树，进而先根遍历此树获得波兰式表达式。<br />    定义了两个结构体：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 58.51%; height: 145px; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Exp{<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">  op;<br />    Item  lhs;<br />    Item  rhs;<br />    Exp(){};<br />    Exp(</span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> _op, Item _lhs, Item _rhs):op(_op), lhs(_lhs), rhs(_rhs){ }<br />    Exp(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> Exp</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> e):op(e.op), lhs(e.lhs), rhs(e.rhs) { }<br />};<br /></span></div><br />表示一个表达式，也是表达式树上的一个子树。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 58.92%; height: 130px; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Item{<br />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">  number;<br />    shared_ptr</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> pExp;<br />    </span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);"> isNumber;<br />    </span><span style="color: rgb(0, 0, 255);">explicit</span><span style="color: rgb(0, 0, 0);"> Item():isNumber(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">), number(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">), pExp(){    }<br />    Item(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> Item</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> i):number(i.number), pExp(i.pExp), isNumber(i.isNumber){ }<br />};<br /></span></div><p><br />表示一个节点，它可以是一个数字，或者一个表达式（pExp这里我使用的是<a href="http://www.boost.org/">boost库</a>的智能指针shared_ptr，所以编译的话，需要先安装boost库）。<br />运行的结果如图：<br /><img src="http://www.cppblog.com/images/cppblog_com/nj-blog/2767/r_print-porland.JPG" /><br />*输入时，以'e'表示输入结束。<br />完整的代码和可执行文件点击<a class="" title="" href="/Files/nj-blog/porland.rar" target="">这里</a>下载。权当抛砖引玉了，希望有更好算法的同学赐教。<br /></p><hr />
完整的代码：<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><img id="Code_Closed_Image" onclick="this.style.display='none'; Code_Closed_Text.style.display='none'; Code_Open_Image.style.display='inline'; Code_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" height="16" width="11" /><img id="Code_Open_Image" style="display: none;" onclick="this.style.display='none'; Code_Open_Text.style.display='none'; Code_Closed_Image.style.display='inline'; Code_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" height="16" width="11" /><span id="Code_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255);"></span><span id="Code_Open_Text" style="display: none;"><br /><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">stack</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">algorithm</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">boost</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">shared_ptr.hpp</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> boost::shared_ptr;<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: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Exp;<br /><img id="Codehighlighter1_178_376_Open_Image" onclick="this.style.display='none'; Codehighlighter1_178_376_Open_Text.style.display='none'; Codehighlighter1_178_376_Closed_Image.style.display='inline'; Codehighlighter1_178_376_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_178_376_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_178_376_Closed_Text.style.display='none'; Codehighlighter1_178_376_Open_Image.style.display='inline'; Codehighlighter1_178_376_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Item</span><span id="Codehighlighter1_178_376_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_178_376_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">  number;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    shared_ptr</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> pExp;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">bool</span><span style="color: rgb(0, 0, 0);"> isNumber;<br /><img id="Codehighlighter1_295_297_Open_Image" onclick="this.style.display='none'; Codehighlighter1_295_297_Open_Text.style.display='none'; Codehighlighter1_295_297_Closed_Image.style.display='inline'; Codehighlighter1_295_297_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_295_297_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_295_297_Closed_Text.style.display='none'; Codehighlighter1_295_297_Open_Image.style.display='inline'; Codehighlighter1_295_297_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">explicit</span><span style="color: rgb(0, 0, 0);"> Item():isNumber(</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">), number(</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">), pExp()</span><span id="Codehighlighter1_295_297_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_295_297_Open_Text"><span style="color: rgb(0, 0, 0);">{    }</span></span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_372_374_Open_Image" onclick="this.style.display='none'; Codehighlighter1_372_374_Open_Text.style.display='none'; Codehighlighter1_372_374_Closed_Image.style.display='inline'; Codehighlighter1_372_374_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_372_374_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_372_374_Closed_Text.style.display='none'; Codehighlighter1_372_374_Open_Image.style.display='inline'; Codehighlighter1_372_374_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Item(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> Item</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> i):number(i.number), pExp(i.pExp), isNumber(i.isNumber)</span><span id="Codehighlighter1_372_374_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_372_374_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_390_572_Open_Image" onclick="this.style.display='none'; Codehighlighter1_390_572_Open_Text.style.display='none'; Codehighlighter1_390_572_Closed_Image.style.display='inline'; Codehighlighter1_390_572_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_390_572_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_390_572_Closed_Text.style.display='none'; Codehighlighter1_390_572_Open_Image.style.display='inline'; Codehighlighter1_390_572_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">struct</span><span style="color: rgb(0, 0, 0);"> Exp</span><span id="Codehighlighter1_390_572_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_390_572_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);">  op;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item  lhs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item  rhs;<br /><img id="Codehighlighter1_442_443_Open_Image" onclick="this.style.display='none'; Codehighlighter1_442_443_Open_Text.style.display='none'; Codehighlighter1_442_443_Closed_Image.style.display='inline'; Codehighlighter1_442_443_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_442_443_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_442_443_Closed_Text.style.display='none'; Codehighlighter1_442_443_Open_Image.style.display='inline'; Codehighlighter1_442_443_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Exp()</span><span id="Codehighlighter1_442_443_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_442_443_Open_Text"><span style="color: rgb(0, 0, 0);">{}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img id="Codehighlighter1_512_514_Open_Image" onclick="this.style.display='none'; Codehighlighter1_512_514_Open_Text.style.display='none'; Codehighlighter1_512_514_Closed_Image.style.display='inline'; Codehighlighter1_512_514_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_512_514_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_512_514_Closed_Text.style.display='none'; Codehighlighter1_512_514_Open_Image.style.display='inline'; Codehighlighter1_512_514_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Exp(</span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> _op, Item _lhs, Item _rhs):op(_op), lhs(_lhs), rhs(_rhs)</span><span id="Codehighlighter1_512_514_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_512_514_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_568_570_Open_Image" onclick="this.style.display='none'; Codehighlighter1_568_570_Open_Text.style.display='none'; Codehighlighter1_568_570_Closed_Image.style.display='inline'; Codehighlighter1_568_570_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_568_570_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_568_570_Closed_Text.style.display='none'; Codehighlighter1_568_570_Open_Image.style.display='inline'; Codehighlighter1_568_570_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Exp(</span><span style="color: rgb(0, 0, 255);">const</span><span style="color: rgb(0, 0, 0);"> Exp</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> e):op(e.op), lhs(e.lhs), rhs(e.rhs) </span><span id="Codehighlighter1_568_570_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_568_570_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_587_712_Open_Image" onclick="this.style.display='none'; Codehighlighter1_587_712_Open_Text.style.display='none'; Codehighlighter1_587_712_Closed_Image.style.display='inline'; Codehighlighter1_587_712_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_587_712_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_587_712_Closed_Text.style.display='none'; Codehighlighter1_587_712_Open_Image.style.display='inline'; Codehighlighter1_587_712_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Error</span><span id="Codehighlighter1_587_712_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_587_712_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> info;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">:<br /><img id="Codehighlighter1_649_651_Open_Image" onclick="this.style.display='none'; Codehighlighter1_649_651_Open_Text.style.display='none'; Codehighlighter1_649_651_Closed_Image.style.display='inline'; Codehighlighter1_649_651_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_649_651_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_649_651_Closed_Text.style.display='none'; Codehighlighter1_649_651_Open_Image.style.display='inline'; Codehighlighter1_649_651_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Error(</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> _info):info(_info)</span><span id="Codehighlighter1_649_651_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_649_651_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_673_675_Open_Image" onclick="this.style.display='none'; Codehighlighter1_673_675_Open_Text.style.display='none'; Codehighlighter1_673_675_Closed_Image.style.display='inline'; Codehighlighter1_673_675_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_673_675_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_673_675_Closed_Text.style.display='none'; Codehighlighter1_673_675_Open_Image.style.display='inline'; Codehighlighter1_673_675_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    Error():info(</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">)</span><span id="Codehighlighter1_673_675_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_673_675_Open_Text"><span style="color: rgb(0, 0, 0);">{ }</span></span><span style="color: rgb(0, 0, 0);"><br /><img id="Codehighlighter1_694_707_Open_Image" onclick="this.style.display='none'; Codehighlighter1_694_707_Open_Text.style.display='none'; Codehighlighter1_694_707_Closed_Image.style.display='inline'; Codehighlighter1_694_707_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_694_707_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_694_707_Closed_Text.style.display='none'; Codehighlighter1_694_707_Open_Image.style.display='inline'; Codehighlighter1_694_707_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);"> what()</span><span id="Codehighlighter1_694_707_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_694_707_Open_Text"><span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> info;}</span></span><span style="color: rgb(0, 0, 0);">   <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_743_936_Open_Image" onclick="this.style.display='none'; Codehighlighter1_743_936_Open_Text.style.display='none'; Codehighlighter1_743_936_Closed_Image.style.display='inline'; Codehighlighter1_743_936_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_743_936_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_743_936_Closed_Text.style.display='none'; Codehighlighter1_743_936_Open_Image.style.display='inline'; Codehighlighter1_743_936_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> printPorland(Exp</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> exp)</span><span id="Codehighlighter1_743_936_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_743_936_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> exp.op ;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(exp.lhs.isNumber)  cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> exp.lhs.number;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> printPorland(</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">exp.lhs.pExp);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(exp.rhs.isNumber)  cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> exp.rhs.number;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> printPorland(</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">exp.rhs.pExp);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);"><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: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> main()<br /><img id="Codehighlighter1_950_2397_Open_Image" onclick="this.style.display='none'; Codehighlighter1_950_2397_Open_Text.style.display='none'; Codehighlighter1_950_2397_Closed_Image.style.display='inline'; Codehighlighter1_950_2397_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_950_2397_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_950_2397_Closed_Text.style.display='none'; Codehighlighter1_950_2397_Open_Image.style.display='inline'; Codehighlighter1_950_2397_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_950_2397_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_950_2397_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    stack</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Item</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">  ExpStack;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">char</span><span style="color: rgb(0, 0, 0);"> tmpChar;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpItem;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpLhs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpRhs;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">  numbers </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">0123456789</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">  operators </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+-*/</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Input the Express(输入 'e'标识结束):</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /><img id="Codehighlighter1_1165_2336_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1165_2336_Open_Text.style.display='none'; Codehighlighter1_1165_2336_Closed_Image.style.display='inline'; Codehighlighter1_1165_2336_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1165_2336_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1165_2336_Closed_Text.style.display='none'; Codehighlighter1_1165_2336_Open_Image.style.display='inline'; Codehighlighter1_1165_2336_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">do</span><span id="Codehighlighter1_1165_2336_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1165_2336_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img id="Codehighlighter1_1171_2183_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1171_2183_Open_Text.style.display='none'; Codehighlighter1_1171_2183_Closed_Image.style.display='inline'; Codehighlighter1_1171_2183_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1171_2183_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1171_2183_Closed_Text.style.display='none'; Codehighlighter1_1171_2183_Open_Image.style.display='inline'; Codehighlighter1_1171_2183_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">try</span><span id="Codehighlighter1_1171_2183_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1171_2183_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img id="Codehighlighter1_1194_1966_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1194_1966_Open_Text.style.display='none'; Codehighlighter1_1194_1966_Closed_Image.style.display='inline'; Codehighlighter1_1194_1966_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1194_1966_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1194_1966_Closed_Text.style.display='none'; Codehighlighter1_1194_1966_Open_Image.style.display='inline'; Codehighlighter1_1194_1966_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(cin</span><span style="color: rgb(0, 0, 0);">&gt;&gt;</span><span style="color: rgb(0, 0, 0);">tmpChar)</span><span id="Codehighlighter1_1194_1966_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1194_1966_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tmpChar </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">e</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">e为结束符</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(find(numbers.begin(), numbers.end(),  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">是一个数字</span><span style="color: rgb(0, 128, 0);"><br /><img id="Codehighlighter1_1320_1421_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1320_1421_Open_Text.style.display='none'; Codehighlighter1_1320_1421_Closed_Image.style.display='inline'; Codehighlighter1_1320_1421_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1320_1421_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1320_1421_Closed_Text.style.display='none'; Codehighlighter1_1320_1421_Open_Image.style.display='inline'; Codehighlighter1_1320_1421_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                    tmpChar)</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">numbers.end())</span><span id="Codehighlighter1_1320_1421_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1320_1421_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                tmpItem.isNumber </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                tmpItem.number   </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> tmpChar;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.push(tmpItem);</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">数字入栈</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(find(operators.begin(), operators.end(), </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">是一个操作符</span><span style="color: rgb(0, 128, 0);"><br /><img id="Codehighlighter1_1511_1903_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1511_1903_Open_Text.style.display='none'; Codehighlighter1_1511_1903_Closed_Image.style.display='inline'; Codehighlighter1_1511_1903_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1511_1903_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1511_1903_Closed_Text.style.display='none'; Codehighlighter1_1511_1903_Open_Image.style.display='inline'; Codehighlighter1_1511_1903_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                    tmpChar)</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">operators.end())</span><span id="Codehighlighter1_1511_1903_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1511_1903_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">操作符每次要对应两个被操作数，否则语法错误</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(ExpStack.size()</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> Error(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Syntactic Error!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">操作符两边的元素出栈</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                tmpRhs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ExpStack.top();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                tmpLhs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ExpStack.top();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                tmpItem.isNumber </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">非数字，是一个表达式</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                tmpItem.pExp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> shared_ptr</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Exp(tmpChar, tmpLhs, tmpRhs)); <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.push(tmpItem);     </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">表达式入栈</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                           <br /><img id="Codehighlighter1_1909_1962_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1909_1962_Open_Text.style.display='none'; Codehighlighter1_1909_1962_Closed_Image.style.display='inline'; Codehighlighter1_1909_1962_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1909_1962_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_1909_1962_Closed_Text.style.display='none'; Codehighlighter1_1909_1962_Open_Image.style.display='inline'; Codehighlighter1_1909_1962_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            }</span></span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> </span><span id="Codehighlighter1_1909_1962_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_1909_1962_Open_Text"><span style="color: rgb(0, 0, 0);">{  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 未知字符</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);">  Error(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Unknow Character!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(ExpStack.size()</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> Error(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Syntactic Error!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        tmpItem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ExpStack.top();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        ExpStack.pop();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(tmpItem.isNumber) cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> tmpItem.number </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> printPorland(</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">tmpItem.pExp);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_2199_2277_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2199_2277_Open_Text.style.display='none'; Codehighlighter1_2199_2277_Closed_Image.style.display='inline'; Codehighlighter1_2199_2277_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_2199_2277_Closed_Image" style="display: none;" onclick="this.style.display='none'; Codehighlighter1_2199_2277_Closed_Text.style.display='none'; Codehighlighter1_2199_2277_Open_Image.style.display='inline'; Codehighlighter1_2199_2277_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    }</span></span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">(Error</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);"> e)</span><span id="Codehighlighter1_2199_2277_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_2199_2277_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> e.what() </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        getline(cin, </span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">());        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">跳过错误的当前行</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">    }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Try again?(y/n)</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&lt;&lt;</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        cin </span><span style="color: rgb(0, 0, 0);">&gt;&gt;</span><span style="color: rgb(0, 0, 0);"> tmpChar;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(tmpChar </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">y</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);"> tmpChar </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Y</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></span></div><img src ="http://www.cppblog.com/nj-blog/aggbug/16011.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-12-05 14:45 <a href="http://www.cppblog.com/nj-blog/archive/2006/12/05/16011.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转载】乔布斯在斯坦福大学的演讲</title><link>http://www.cppblog.com/nj-blog/archive/2006/11/05/14704.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Sun, 05 Nov 2006 13:30:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/11/05/14704.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/14704.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/11/05/14704.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/14704.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/14704.html</trackback:ping><description><![CDATA[
		<p>转自<a class="" title="" href="http://www.zhuoqun.net/" target=""><font color="#0000ff">Dreamer's Blog</font><br /></a><br />      今天在网上无意中发现了苹果电脑之父乔布斯在斯坦福大学的演讲，他在演讲中说了三个关于自己的故事，我看了之后很有感触。今天把原文和译文都发上来，供大家参考。另外<a href="http://www.youtube.com/watch?v=D1R-jKKp3NA" target="_blank" tip="">这里有YouTube上的视频</a>观看。<a href="http://uschools.com:8000/Members/administrator/Uschools.com_Discussion_Forums/Member%20Discussion%20Forums/edu/301583579097/forum_topic" target="_blank" tip="">这里有演讲mp3下载。</a><br /><br />      Steve Jobs说，你得找出你爱的 (You've got to find what you love.)。 <br /><br />      以下是苹果计算机公司与Pixar动画制作室执行长Steve Jobs在2005年六月12日对全体史丹佛大学毕业生的演讲内容：<br /><br />      今天，有荣幸来到各位从世界上最好的学校之一毕业的毕业典礼上。我从来没从大学毕业。说实话，这是我离大学毕业最近的一刻。今天，我只说三个故事，不谈大道理，三个故事就好。 <br /><br />      第一个故事，是关于人生中的点点滴滴怎么串连在一起。 <br /><br />      我在里德学院（Reed college）待了六个月就办休学了。到我退学前，一共休学了十八个月。那么，我为什么休学？ <br /><br />      这得从我出生前讲起。我的亲生母亲当时是个研究生，年轻未婚妈妈，她决定让别人收养我。她强烈觉得应该让有大学毕业的人收养我，所以我出生时，她就准备让我被一对律师夫妇收养。但是这对夫妻到了最后一刻反悔了，他们想收养女孩。所以在等待收养名单上的一对夫妻，我的养父母，在一天半夜里接到一通电话，问他们「有一名意外出生的男孩，你们要认养他吗？」而他们的回答是「当然要」。后来，我的生母发现，我现在的妈妈从来没有大学毕业，我现在的爸爸则连高中毕业也没有。她拒绝在认养文件上做最后签字。直到几个月后，我的养父母同意将来一定会让我上大学，她才软化态度。 <br /><br />      十七年后，我上大学了。但是当时我无知选了一所学费几乎跟史丹佛一样贵的大学，我那工人阶级的父母所有积蓄都花在我的学费上。六个月后，我看不出念这个书的价值何在。那时候，我不知道这辈子要干什么，也不知道念大学能对我有什么帮助，而且我为了念这个书，花光了我父母这辈子的所有积蓄，所以我决定休学，相信船到桥头自然直。当时这个决定看来相当可怕，可是现在看来，那是我这辈子做过最好的决定之一。当我休学之后，我再也不用上我没兴趣的必修课，把时间拿去听那些我有兴趣的课。 <br /><br />      这一点也不浪漫。我没有宿舍，所以我睡在友人家里的地板上，靠着回收可乐空罐的五先令退费买吃的，每个星期天晚上得走七里的路绕过大半个镇去印度教的Hare Krishna神庙吃顿好料。我喜欢Hare Krishna神庙的好料。追寻我的好奇与直觉，我所驻足的大部分事物，后来看来都成了无价之宝。举例来说： <br /><br />      当时里德学院有着大概是全国最好的书法指导。在整个校园内的每一张海报上，每个抽屉的标签上，都是美丽的手写字。因为我休学了，可以不照正常选课程序来，所以我跑去学书法。我学了serif与san serif字体，学到在不同字母组合间变更字间距，学到活版印刷伟大的地方。书法的美好、历史感与艺术感是科学所无法捕捉的，我觉得那很迷人。 <br /><br />      我没预期过学的这些东西能在我生活中起些什么实际作用，不过十年后，当我在设计第一台麦金塔时，我想起了当时所学的东西，所以把这些东西都设计进了麦金塔里，这是第一台能印刷出漂亮东西的计算机。如果我没沉溺于那样一门课里，麦金塔可能就不会有多重字体跟变间距字体了。又因为Windows抄袭了麦金塔的使用方式，如果当年我没这样做，大概世界上所有的个人计算机都不会有这些东西，印不出现在我们看到的漂亮的字来了。当然，当我还在大学里时，不可能把这些点点滴滴预先串在一起，但是这在十年后回顾，就显得非常清楚。 <br /><br /><span style="COLOR: red">      我再说一次，你不能预先把点点滴滴串在一起；唯有未来回顾时，你才会明白那些点点滴滴是如何串在一起的。所以你得相信，你现在所体会的东西，将来多少会连接在一块。你得信任某个东西，直觉也好，命运也好，生命也好，或者业力。这种作法从来没让我失望，也让我的人生整个不同起来。 </span><br /><br />      我的第二个故事，有关爱与失去。 <br /><br />      我好运－年轻时就发现自己爱做什么事。我二十岁时，跟Steve Wozniak在我爸妈的车库里开始了苹果计算机的事业。我们拼命工作，苹果计算机在十年间从一间车库里的两个小伙子扩展成了一家员工超过四千人、市价二十亿美金的公司，在那之前一年推出了我们最棒的作品－麦金塔，而我才刚迈入人生的第三十个年头，然后被炒鱿鱼。要怎么让自己创办的公司炒自己鱿鱼？好吧，当苹果计算机成长后，我请了一个我以为他在经营公司上很有才干的家伙来，他在头几年也确实干得不错。可是我们对未来的愿景不同，最后只好分道扬镳，董事会站在他那边，炒了我鱿鱼，公开把我请了出去。曾经是我整个成年生活重心的东西不见了，令我不知所措。 <br /><br />      有几个月，我实在不知道要干什么好。我觉得我令企业界的前辈们失望－我把他们交给我的接力棒弄丢了。我见了创办HP的David Packard跟创办Intel的Bob Noyce，跟他们说我很抱歉把事情搞砸得很厉害了。我成了公众的非常负面示范，我甚至想要离开硅谷。但是渐渐的，我发现，我还是喜爱着我做过的事情，在苹果的日子经历的事件没有丝毫改变我爱做的事。我被否定了，可是我还是爱做那些事情，所以我决定从头来过。 <br /><br />      当时我没发现，但是现在看来，被苹果计算机开除，是我所经历过最好的事情。成功的沉重被从头来过的轻松所取代，每件事情都不那么确定，让我自由进入这辈子最有创意的年代。 <br /><br />      接下来五年，我开了一家叫做NeXT的公司，又开一家叫做Pixar的公司，也跟后来的老婆谈起了恋爱。Pixar接着制作了世界上第一部全计算机动画电影，玩具总动员，现在是世界上最成功的动画制作公司。然后，苹果计算机买下了NeXT，我回到了苹果，我们在NeXT发展的技术成了苹果计算机后来复兴的核心。我也有了个美妙的家庭。 <br /><br />      我很确定，如果当年苹果计算机没开除我，就不会发生这些事情。这帖药很苦口，可是我想苹果计算机这个病人需要这帖药。<span style="COLOR: red">有时候，人生会用砖头打你的头。不要丧失信心。我确信，我爱我所做的事情，这就是这些年来让我继续走下去的唯一理由。你得找出你爱的，工作上是如此，对情人也是如此。你的工作将填满你的一大块人生，唯一获得真正满足的方法就是做你相信是伟大的工作，而唯一做伟大工作的方法是爱你所做的事。如果你还没找到这些事，继续找，别停顿。尽你全心全力，你知道你一定会找到。而且，如同任何伟大的关系，事情只会随着时间愈来愈好。所以，在你找到之前，继续找，别停顿。 </span><br /><br /><br />      我的第三个故事，关于死亡。 <br /><br />      当我十七岁时，我读到一则格言，好像是「把每一天都当成生命中的最后一天，你就会轻松自在。」这对我影响深远，在过去33年里，我每天早上都会照镜子，自问：「如果今天是此生最后一日，我今天要干些什么？」每当我连续太多天都得到一个「没事做」的答案时，我就知道我必须有所变革了。 <br /><br />      提醒自己快死了，是我在人生中下重大决定时，所用过最重要的工具。因为几乎每件事－所有外界期望、所有名誉、所有对困窘或失败的恐惧－在面对死亡时，都消失了，只有最重要的东西才会留下。提醒自己快死了，是我所知避免掉入自己有东西要失去了的陷阱里最好的方法。人生不带来，死不带去，没什么道理不顺心而为。 <br /><br />      一年前，我被诊断出癌症。我在早上七点半作断层扫描，在胰脏清楚出现一个肿瘤，我连胰脏是什么都不知道。医生告诉我，那几乎可以确定是一种不治之症，我大概活不到三到六个月了。医生建议我回家，好好跟亲人们聚一聚，这是医生对临终病人的标准建议。那代表你得试着在几个月内把你将来十年想跟小孩讲的话讲完。那代表你得把每件事情搞定，家人才会尽量轻松。那代表你得跟人说再见了。 <br />   <br />      我整天想着那个诊断结果，那天晚上做了一次切片，从喉咙伸入一个内视镜，从胃进肠子，插了根针进胰脏，取了一些肿瘤细胞出来。我打了镇静剂，不醒人事，但是我老婆在场。她后来跟我说，当医生们用显微镜看过那些细胞后，他们都哭了，因为那是非常少见的一种胰脏癌，可以用手术治好。所以我接受了手术，康复了。 <br /><br />      这是我最接近死亡的时候，我希望那会继续是未来几十年内最接近的一次。经历此事后，我可以比之前死亡只是抽象概念时要更肯定告诉你们下面这些： <br /><br />      没有人想死。即使那些想上天堂的人，也想活着上天堂。但是死亡是我们共有的目的地，没有人逃得过。这是注定的，因为死亡简直就是生命中最棒的发明，是生命变化的媒介，送走老人们，给新生代留下空间。现在你们是新生代，但是不久的将来，你们也会逐渐变老，被送出人生的舞台。抱歉讲得这么戏剧化，但是这是真的。 <br /><br /><span style="COLOR: red">      你们的时间有限，所以不要浪费时间活在别人的生活里。不要被信条所惑－盲从信条就是活在别人思考结果里。不要让别人的意见淹没了你内在的心声。最重要的，拥有跟随内心与直觉的勇气，你的内心与直觉多少已经知道你真正想要成为什么样的人。任何其它事物都是次要的。 </span><br /><br />      在我年轻时，有本神奇的杂志叫做Whole Earth Catalog，当年我们很迷这本杂志。那是一位住在离这不远的Menlo Park的Stewart Brand发行的，他把杂志办得很有诗意。那是1960年代末期，个人计算机跟桌上出版还没发明，所有内容都是打字机、剪刀跟拍立得相机做出来的。杂志内容有点像印在纸上的Google，在Google出现之前35年就有了：理想化，充满新奇工具与神奇的注记。 <br /><br />      Stewart跟他的出版团队出了好几期Whole Earth Catalog，然后出了停刊号。当时是1970年代中期，我正是你们现在这个年龄的时候。在停刊号的封底，有张早晨乡间小路的照片，那种你去爬山时会经过的乡间小路。在照片下有行小字： <br /><span style="COLOR: red">      求知若饥，虚心若愚。 </span><br /><br />      那是他们亲笔写下的告别讯息，我总是以此自许。当你们毕业，展开新生活，我也以此期许你们。 <br /><br />      求知若饥，虚心若愚。 <br /><br />      非常谢谢大家。 <br /><br /><strong>原文：</strong><br /><br />Stanford Report, June 14, 2005 <br /><br />'You've got to find what you love,' Jobs says <br /><br />This is the text of the Commencement address by Steve Jobs, CEO of Apple Computer and of Pixar Animation Studios, delivered on June 12, 2005. <br /><br />I am honored to be with you today at your commencement from one of the finest universities in the world. I never graduated from college. Truth be told, this is the closest I've ever gotten to a college graduation. Today I want to tell you three stories from my life. That's it. No big deal. Just three stories. <br /><br />The first story is about connecting the dots. <br /><br />I dropped out of Reed College after the first 6 months, but then stayed around as a drop-in for another 18 months or so before I really quit. So why did I drop out? <br /><br />It started before I was born. My biological mother was a young, unwed college graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife. Except that when I popped out they decided at the last minute that they really wanted a girl. So my parents, who were on a waiting list, got a call in the middle of the night asking: "We have an unexpected baby boy; do you want him?" They said: "Of course." My biological mother later found out that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would someday go to college. <br /><br />And 17 years later I did go to college. But I naively chose a college that was almost as expensive as Stanford, and all of my working-class parents' savings were being spent on my college tuition. After six months, I couldn't see the value in it. I had no idea what I wanted to do with my life and no idea how college was going to help me figure it out. And here I was spending all of the money my parents had saved their entire life. So I decided to drop out and trust that it would all work out OK. It was pretty scary at the time, but looking back it was one of the best decisions I ever made. The minute I dropped out I could stop taking the required classes that didn't interest me, and begin dropping in on the ones that looked interesting. <br /><br />It wasn't all romantic. I didn't have a dorm room, so I slept on the floor in friends' rooms, I returned coke bottles for the 5?? deposits to buy food with, and I would walk the 7 miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example: <br /><br />Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer, was beautifully hand calligraphed. Because I had dropped out and didn't have to take the normal classes, I decided to take a calligraphy class to learn how to do this. I learned about serif and san serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can't capture, and I found it fascinating. <br /><br />None of this had even a hope of any practical application in my life. But ten years later, when we were designing the first Macintosh computer, it all came back to me. And we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the Mac would have never had multiple typefaces or proportionally spaced fonts. And since Windows just copied the Mac, its likely that no personal computer would have them. If I had never dropped out, I would have never dropped in on this calligraphy class, and personal computers might not have the wonderful typography that they do. Of course it was impossible to connect the dots looking forward when I was in college. But it was very, very clear looking backwards ten years later. <br /><br />Again, you can't connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something - your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life. <br /><br />My second story is about love and loss. <br /><br />I was lucky - I found what I loved to do early in life. Woz and I started Apple in my parents garage when I was 20. We worked hard, and in 10 years Apple had grown from just the two of us in a garage into a $2 billion company with over 4000 employees. We had just released our finest creation - the Macintosh - a year earlier, and I had just turned 30. And then I got fired. How can you get fired from a company you started? Well, as Apple grew we hired someone who I thought was very talented to run the company with me, and for the first year or so things went well. But then our visions of the future began to diverge and eventually we had a falling out. When we did, our Board of Directors sided with him. So at 30 I was out. And very publicly out. What had been the focus of my entire adult life was gone, and it was devastating. <br /><br />I really didn't know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down - that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly. I was a very public failure, and I even thought about running away from the valley. But something slowly began to dawn on me - I still loved what I did. The turn of events at Apple had not changed that one bit. I had been rejected, but I was still in love. And so I decided to start over. <br /><br />I didn't see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods of my life. <br /><br />During the next five years, I started a company named NeXT, another company named Pixar, and fell in love with an amazing woman who would become my wife. Pixar went on to create the worlds first computer animated feature film, Toy Story, and is now the most successful animation studio in the world. In a remarkable turn of events, Apple bought NeXT, I retuned to Apple, and the technology we developed at NeXT is at the heart of Apple's current renaissance. And Laurene and I have a wonderful family together.    <br /><br />I'm pretty sure none of this would have happened if I hadn't been fired from Apple. It was awful tasting medicine, but I guess the patient needed it. Sometimes life hits you in the head with a brick. Don't lose faith. I'm convinced that the only thing that kept me going was that I loved what I did. You've got to find what you love. And that is as true for your work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don't settle. <br /><br />My third story is about death. <br /><br />When I was 17, I read a quote that went something like: "If you live each day as if it was your last, someday you'll most certainly be right." It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself: "If today were the last day of my life, would I want to do what I am about to do today?" And whenever the answer has been "No" for too many days in a row, I know I need to change something. <br /><br />Remembering that I'll be dead soon is the most important tool I've ever encountered to help me make the big choices in life. Because almost everything - all external expectations, all pride, all fear of embarrassment or failure - these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart. <br /><br />About a year ago I was diagnosed with cancer. I had a scan at 7:30 in the morning, and it clearly showed a tumor on my pancreas. I didn't even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months. My doctor advised me to go home and get my affairs in order, which is doctor's code for prepare to die. It means to try to tell your kids everything you thought you'd have the next 10 years to tell them in just a few months. It means to make sure everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes. <br /><br />I lived with that diagnosis all day. Later that evening I had a biopsy, where they stuck an endoscope down my throat, through my stomach and into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated, but my wife, who was there, told me that when they viewed the cells under a microscope the doctors started crying because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and I'm fine now. <br /><br />This was the closest I've been to facing death, and I hope its the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept: <br /><br />No one wants to die. Even people who want to go to heaven don't want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Life's change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true. <br /><br />Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma - which is living with the results of other people's thinking. Don't let the noise of other's opinions drown out your own inner voice. And most important,  have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary. <br /><br />When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960's, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: it was idealistic, and overflowing with neat tools and great notions. <br /><br />Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: "Stay Hungry. Stay Foolish." It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you. <br /><br />Stay Hungry. Stay Foolish. <br /><br />Thank you all very much.</p>
<img src ="http://www.cppblog.com/nj-blog/aggbug/14704.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-11-05 21:30 <a href="http://www.cppblog.com/nj-blog/archive/2006/11/05/14704.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Scott Meyers最近一次Aha！时刻</title><link>http://www.cppblog.com/nj-blog/archive/2006/11/03/14595.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Thu, 02 Nov 2006 17:10:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/11/03/14595.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/14595.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/11/03/14595.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/14595.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/14595.html</trackback:ping><description><![CDATA[    孟岩在自己的blog上<a title="提到了" href="http://blog.csdn.net/myan/archive/2006/09/17/1232960.aspx">提到了</a> Scott Meyers在Artima.com的C++ Source栏目中发表的一个5×5的系列。其中最后一篇是Scott Meyers的<a title="五个最重要的C++Aha！时刻" href="http://www.artima.com/cppsource/top_cpp_aha_moments.html">五个最重要的C++Aha！时刻</a> ，孟岩提示大家关注最后一个。如果关注过Scott Meyers和他的Effectiv系列的话，对他前四个Aha！时刻应该都已经熟识了。<br /><div>    这里仅翻译第五个：<br /><h3>明白Boost的<span style="FONT-STYLE: italic">shared_ptr</span>里<span style="FONT-STYLE: italic">deleter</span>是如何工作的，2004 </h3>Boost的引用计数智能指针shared_ptr有一个有趣的特性，你可以传入一个函数或者一个函数体，并且当引<br />用计数为零时，它会对指向的对象调用这个deleter。让人脸红的是，这看起来很平凡，但是请看这段代码：<br /><br /><span style="COLOR: rgb(0,153,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(0,153,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(0,0,0)"><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">template</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">typename  T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">  shared_ptr {<br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br />    template</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">typename U, typename D</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">explicit</span><span style="COLOR: #000000">  shared_ptr(U</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> ptr, D deleter);<br />    <img src="http://www.cppblog.com/images/dot.gif" /><br />};<br /></span></div><br /></span></span></span></span></span>要注意的是在析构的期间shared_ptr&lt;T&gt;必须为类型为D的deleter做些安排，以确保它的调用，然而shared_ptr&lt;T&gt;并不知道类型D到底是什么。此对象不能包含类型为D的数据成员，当然也不能有一个指向类型为D的对象的指针，因为当对象成员数据声明的时候对于D好不知情。那么shared_ptr对象如何在构造期deleter被传入时保存它的踪迹，并且在稍后的析构期使用它的呐？更一般的说法，在一个对象的构造期间构造函数如何获得未知类型的信息，并把类型的信息传给此对象，而对象不能保存关于此类型任何提示。<br /><br />答案很简单：此对象包含一个已知类型的基类指针（Boost管它叫做 sp_counted_base ），指向一个已经构造实例化的模板，此模板继承自前面的基类，并使用D作为实例化参数（Boost使用模板 sp_counted_impl_p 和 sp_counted_impl_pd ），使用一个在基类里声明，继承类中定义的虚函数来调用 deleter （Boost使用 dispose ）。稍微简化了，它看起来像下面这样：<br />                            <img height="156" src="http://docs.google.com/File?id=dcjhdv5v_16f63d7b" width="343" align="absMiddle" /> <br />它是很明显的，只要你看过它一次。但是只要你看过它一次，你就会体会到它可以被用到很多种类的地方，它打开了模板设计的新视野，模板化类使用相对较少的模板参数（shared_ptr 只是其中一个）可以引用不受数量限制的当前不知名类型的信息。当我意识到我接近的东西，我不能禁止地露出赞赏的笑容并摇晃我的脑袋。<br /><br /></div><img src ="http://www.cppblog.com/nj-blog/aggbug/14595.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-11-03 01:10 <a href="http://www.cppblog.com/nj-blog/archive/2006/11/03/14595.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Message Crack Wizard for Win32 SDK Developer</title><link>http://www.cppblog.com/nj-blog/archive/2006/11/02/14559.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Wed, 01 Nov 2006 16:00:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/11/02/14559.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/14559.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/11/02/14559.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/14559.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/14559.html</trackback:ping><description><![CDATA[本文译自<a class="" title="" href="www.codeproject.com" target="_blank">codeproject.com</a>，原文链接与工具及其源代码下载点击<a class="" title="" href="http://www.codeproject.com/win32/msgcrackwizard.asp" target="_blank">这里</a>。<br />－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br /> <span style="COLOR: rgb(255,153,0)">导引：WINDOWSX.H头文件简化Win32 SDK编程</span><br /><br />许多的新手或者调试程序员在编写C/C++的Windows API程序时都要面对像意大利面一样的<span style="COLOR: rgb(51,102,255)">switch...case<span style="COLOR: rgb(51,0,51)"><span style="COLOR: rgb(0,0,0)">代码块。当你需要加入一个消息处理到你的窗口处理过程中时，在些代码块中查找例如：<span style="COLOR: rgb(255,0,0)">WM_COMMAND</span>或<span style="COLOR: rgb(255,0,0)">WM_CHAR</span>，是相当让人恐惧的事情。<br /><br />早在Windows 3.1时代的Windows软件开发工具包和C/C++7.0编译器就附带一个包含一千多行Windows处理代码的头文件。这个头文件是<span style="FONT-STYLE: italic">&lt;windowsX.h&gt;</span>，它包含<br />了许多有用的宏。微软的对这个头文件的介绍如下：<br /></span></span></span><br /><ul><li>对C程序做更严格的类型检查的<span style="COLOR: rgb(255,0,0)">STRICT</span>宏。 
</li><li>一些简化Windows编程的通用操作的宏。 
</li><li>一些简化与Windows控件交流的控件宏。 
</li><li>消息分流器（一种方便，轻便并且类型安全的处理消息的方法）以及它们在Windows环境下的参数和返回值。 </li></ul><br />在Message Cracker Wizard被设计出现之前，我就从使用这些的宏中获得了效率。如果你对<span style="FONT-STYLE: italic">Windows.h</span>的简单描述感兴趣，你可以参见MS知识库的文章<a title="#8356" href="http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q83/4/56.asp">#8356</a> 。<br /><br />好了，让我们来介绍消息分流器的便利，以及，为什么这里发布的工具可以你编写代码的效率。<br /><br />当你在编写Win32 SDK程序时，你处理窗口消息通过一个窗口函数，通常命名为<span style="COLOR: rgb(255,0,0)">WndProc<span style="COLOR: rgb(0,0,0)">。在Windows C 程序中常见的是窗口函数通过关键字<span style="COLOR: rgb(51,51,255)">switch<span style="COLOR: rgb(0,0,0)">和分支标签<span style="COLOR: rgb(51,51,255)">case<span style="COLOR: rgb(0,0,0)">处理所有你需要处理的消息。<br /><br />可以料想的是我们通常需要在主窗口中处理<span style="COLOR: rgb(255,0,0)">WM_COMMAND<span style="COLOR: rgb(0,0,0)">，</span>WM_KEYUP<span style="COLOR: rgb(0,0,0)">，</span>WM_CLOSE<span style="COLOR: rgb(0,0,0)">和</span>WM_DESTROY<span style="COLOR: rgb(0,0,0)">消息。理论上我们会把窗口函数写成这样：<br /></span></span></span></span></span></span></span></span><span name="intelliTxt"></span><span name="intelliTxt"><pre><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="Times New Roman"><span style="COLOR: #000000">LRESULT CALLBACK MainWndProc (HWND hwnd, UINT msg,   WPARAM wParam, LPARAM lParam)<br />{<br />  </span><span style="COLOR: #0000ff">switch</span></font><font face="Times New Roman"><span style="COLOR: #000000">(msg)<br />  {<br />    </span><span style="COLOR: #0000ff">case</span></font><font face="Times New Roman"><span style="COLOR: #000000"> WM_COMMAND:<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> <img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #008000"><br /></span><font face="Times New Roman"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">break</span></font><font face="Times New Roman"><span style="COLOR: #000000">;    <br />     <br />    </span><span style="COLOR: #0000ff">case</span></font><font face="Times New Roman"><span style="COLOR: #000000"> WM_KEYUP:<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> <img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #008000"><br /></span><font face="Times New Roman"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">break</span></font><font face="Times New Roman"><span style="COLOR: #000000">;<br /><br />    </span><span style="COLOR: #0000ff">case</span></font><font face="Times New Roman"><span style="COLOR: #000000"> WM_CLOSE:<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> <img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #008000"><br /></span><font face="Times New Roman"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">break</span></font><font face="Times New Roman"><span style="COLOR: #000000">;       <br />     <br />    </span><span style="COLOR: #0000ff">case</span></font><font face="Times New Roman"><span style="COLOR: #000000"> WM_DESTROY:<br />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #008000"><br /></span><font face="Times New Roman"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">break</span></font><font face="Times New Roman"><span style="COLOR: #000000">;      <br />        <br />    </span><span style="COLOR: #0000ff">default</span></font><font face="Times New Roman"><span style="COLOR: #000000">:   <br />       </span><span style="COLOR: #0000ff">return</span></font><span style="COLOR: #000000"><font face="Times New Roman"> DefWindowProc(hwnd, msg, wParam, lParam);<br />  }<br />}</font></span></div></pre></span>这是自Windows 1.0时代以来处理Windows消息使用最多的，确实地，它工作。但是问题是当你开始向你程序中加入更多复杂的特性，例如 MDI，OLE，通用控件，等等，你会获得一个行数以千记的窗口函数。你开始反复使用PageDn和PageUp键跳跃，来寻找你需要修改的消息。<br /><br />这是使用消息分流器的第一个好处：它们提供了处理函数来简化<span style="COLOR: rgb(51,51,255)">case<span style="COLOR: rgb(0,0,0)">标签意大利面，就像MFC做的那样。<br /><br />第二个好处是正确的参数规范化了你的处理函数的使用。你可以简单地使用<span style="COLOR: rgb(51,51,255)">switch<span style="COLOR: rgb(204,0,0)">(id)<span style="COLOR: rgb(0,0,0)">来替代</span></span></span><span style="COLOR: rgb(51,51,255)">switch<span style="COLOR: rgb(204,0,0)">(LOWORD(wparam))<span style="COLOR: rgb(0,0,0)">，因为你把<span style="COLOR: rgb(204,0,0)">id<span style="COLOR: rgb(0,0,0)">作为一个“分流器”的参数传递给消息函数时，等同于<span style="COLOR: rgb(204,0,0)">LOWORD(wparam)<span style="COLOR: rgb(0,0,0)">。<br /><br />消息处理宏<span style="COLOR: rgb(204,0,0)">HANDLE_MSG<span style="COLOR: rgb(0,0,0)">定义在<span style="FONT-STYLE: italic">windows.h</span>中，如下：</span></span></span></span></span></span></span></span></span></span></span><span class="cpp-preprocessor" style="COLOR: rgb(0,0,153)"><span style="FONT-FAMILY: monospace"><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"><font face="Times New Roman"><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000"> HANDLE_MSG(hwnd, message, fn) \</span></font><span style="COLOR: #000000"><br /><font face="Times New Roman">    </font></span><font face="Times New Roman"><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> (message) : </span><span style="COLOR: #0000ff">return</span></font><span style="COLOR: #000000"><font face="Times New Roman"> HANDLE_##message((hwnd), (wParam), (lParam), (fn)) <br /></font></span></div><br /></span></span><span name="intelliTxt">如你从上面宏定义中可以想到的是，将你的代码转换成“消息分流器”版本，你必须支持分流宏，<span style="COLOR: rgb(204,0,0)">HANDLE_MSG<span style="COLOR: rgb(0,0,0)">，并且使用函数来处理消息。现在将<span style="COLOR: rgb(204,0,0)">HANDLE_MSG<span style="COLOR: rgb(0,0,0)">宏加入到窗口函数中来。这个宏需要三个参数：一个窗口句柄(<span style="COLOR: rgb(204,0,0)">hwnd</span>)<span style="COLOR: rgb(0,0,0)">，你要处理的消息(<span style="COLOR: rgb(204,0,0)">WM_xxxx</span>)<span style="COLOR: rgb(0,0,0)">，以及你用来处理此消息的函数。为了更好的说明，我把之前的窗口函数替换成下面的消息分流版：<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: #000000">LRESULT CALLBACK MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)<br />{<br />  </span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">(msg)<br />  {<br />    HANDLE_MSG (hwnd, WM_COMMAND, OnCommand);<br />    HANDLE_MSG (hwnd, WM_KEYUP,   OnKeyup);<br />    HANDLE_MSG (hwnd, WM_CLOSE,   OnClose);<br />    HANDLE_MSG (hwnd, WM_DESTROY, OnDestroy);<br />    </span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">:<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> DefWindowProc(hwnd, msg, wParam, lParam);<br />  }<br />}<br /></span></div><br /><br /></span></span></span></span></span></span></span>哇！这是更好的，简洁的并且容易控制的窗口函数。现在你需要定义的的消息处理函数(<span style="COLOR: rgb(204,0,0)">OnKeyUp, OnClose<span style="COLOR: rgb(0,0,0)">和<span style="COLOR: rgb(204,0,0)">OnDestroy</span></span></span>)。更加便利的是你可以使用Visual Studio IDE跳到你消息处理函数：<br /><img title="ide1" src="http://docs.google.com/File?id=dcjhdv5v_4gpjjqq" /><br /><br />问题是每一次你增加一个消息处理你都必须搜寻<span style="FONT-STYLE: italic">WINDOWS.H</span>里的定义，以匹配你的消息处理函数的参数类型，因为你不能随意的使用参数类型：处理函数的格式是清楚定义的。在头文件中反复的查找是单调乏味的任务，且容易出错。消息分流器Wizard工具来搭救你了：它允许你粘贴任何你需要的消息处理的正确的参数。如果你刚刚开始编写代码，它还可以生成一个窗口模板或者对话框函数作为你处理窗口消息的开始。<br /><br /><span style="COLOR: rgb(255,153,0)"><span style="FONT-WEIGHT: bold">Message forwarding</span>宏：另一个WINDOWS.H特色<br /><br /><span style="COLOR: rgb(0,0,0)">头文件<span style="FONT-STYLE: italic">windowsx.h</span>的另一个特色大约是<span style="FONT-WEIGHT: bold">message forwarding</span>。它用来“拆除”消息处理函数的参数为有效的<span style="COLOR: rgb(204,0,0)">WPARAM<span style="COLOR: rgb(0,0,0)">和<span style="COLOR: rgb(204,0,0)">LPARAM<span style="COLOR: rgb(0,0,0)">的值</span></span></span></span>，以调用诸如<span style="COLOR: rgb(204,0,0)">PostMessage<span style="COLOR: rgb(0,0,0)">，<span style="COLOR: rgb(204,0,0)">SendMessage<span style="COLOR: rgb(0,0,0)">，<span style="COLOR: rgb(204,0,0)">CallWindowProc<span style="COLOR: rgb(0,0,0)">等等，此类的函数。<br /><br /><br />假设你你希望使用<span style="COLOR: rgb(204,0,0)">SendMessage<span style="COLOR: rgb(0,0,0)">函数来发送<span style="COLOR: rgb(204,0,0)">WM_COMMAND<span style="COLOR: rgb(0,0,0)">消息给父窗口，通过以一个通知码<span style="COLOR: rgb(204,0,0)">BN_DBLCLK<span style="COLOR: rgb(0,0,0)">来“模拟”双击一个命名为<span style="COLOR: rgb(204,0,0)">IDC_USERCTL<span style="COLOR: rgb(0,0,0)">的控件。你通常会这样写：<br /><br /></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span style="FONT-FAMILY: monospace"></span>SendMessage (hwndParent, WM_COMMAND, <span style="FONT-FAMILY: monospace"><br /></span>    MAKEWPARAM(IDC_USERCTL, BN_DBLCLK),<br />     (LPARAM)GetDlgItem(hwnd, ID_USERCTL));<br /><br /><span name="intelliTxt">这是一个复杂的的语法：函数<span style="COLOR: rgb(204,0,0)">SendMessage<span style="COLOR: rgb(0,0,0)">期望<span style="COLOR: rgb(0,0,0)">WPARAM参数的底字节是控件的ID，高字节是通知码；并且我们要通过API函数<span style="COLOR: rgb(204,0,0)">GetDlgItem<span style="COLOR: rgb(0,0,0)">获得控件句柄，传给</span>LPARAM<span style="COLOR: rgb(0,0,0)">参数。<br /><br />上面的代码可以用<span style="FONT-STYLE: italic">Windows.h</span>的message forwarding宏替换，<span style="COLOR: rgb(204,0,0)">FORWARD_WM_XXXX<span style="COLOR: rgb(0,0,0)">。对于每一个消息，forwarding宏都使用和消息分流器生成的消息处理函数相同的“捆扎”参数，增加你希望调用的函数并且传给它“拆除”后的<span style="COLOR: rgb(204,0,0)">LPARAM<span style="COLOR: rgb(0,0,0)">/<span style="COLOR: rgb(204,0,0)">WPARAM<span style="COLOR: rgb(0,0,0)">s。例如，消息分流器Wizard为<span style="COLOR: rgb(204,0,0)">WM_COMMAND<span style="COLOR: rgb(0,0,0)">消息和窗口ID<span style="COLOR: rgb(204,0,0)">myWnd<span style="COLOR: rgb(0,0,0)">生成如下的函数原型：<br /></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span name="intelliTxt"><pre><font face="Times New Roman"><span class="cpp-keyword">void</span> myWnd_OnCommand (HWND hwnd, <span class="cpp-keyword">int</span> id, HWND hwndCtl, UINT codeNotify)</font></pre></span><span name="intelliTxt"><pre><span class="cpp-keyword"><font face="Times New Roman">好了，这些分流器参数也同样被用于forwarding宏--因此，如你所期望的，我们之前调用</font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman">SendMessage</font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">函数时展现的混乱可以减少了：<br /></font></span></span></span><span name="intelliTxt"><pre><font face="Times New Roman">FORWARD_WM_COMMAND (hwndParent, IDC_USERCTL, <br />  GetDlgItem(hwnd, ID_USERCTL), BN_DBLCLK, SendMessage);</font></pre></span><font face="Times New Roman">这种方式非常简便，并且可以为所有消息分流器Wizard支持的消息工作。<br /></font><span class="cpp-keyword"><span style="FONT-FAMILY: Verdana"><br /></span></span><br /><font face="Times New Roman"><span style="COLOR: rgb(255,153,0)">使用消息分流Wizard工具</span><br /><br />当你运行消息分流器Wizard时，你可以看到下面的窗口：<br /><br /><img title="MCW" src="http://docs.google.com/File?id=dcjhdv5v_7g4cnpf" /><br /><br />Wizard在左上角的列表框里为你提供了<span style="FONT-STYLE: italic">WINDOWS.H</span>里有的消息处理，你可以点击一个或者多个消息。你可以在窗口ID编辑框里指定一个窗口标识，以指定你要发送消息的<br />窗口。通用的ID有 </font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman">MainWnd ，About </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">(关于对话框），等等。这个标识会体现在消息处理函数中，和 </font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman">HANDLE_MSG </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">宏中，如果你刚刚开始编写代码，它还可以体现在窗<br />口/对话框处理函数中。“ <span style="FONT-WEIGHT: bold">Make Window Procedure</span>”选定框的作用是：允许你通过选定的消息分流器的宏来生成一个窗口/对话框函数的框架。以这种方式来开始一<br />个Windows API项目，你可以清晰的编写和组织你的代码，当然还有，避免错误。在窗口下面的两个编辑框会包含分流器的宏和处理所选消息的函数（只是原型）生成的代<br />码。要注意的是，当你选择“<span style="FONT-WEIGHT: bold">Make Window Procedure</span>”时窗口处理函数的模板代码不出现在这里：它仅体现在你点击了“<span style="FONT-WEIGHT: bold">Copy Macro</span>”时复制到你的C++编辑器中<br />的代码里。<br /><br />让我们通过例子来快速的浏览消息分流器Wizard工具的特性。记住你必须先通过<span style="FONT-STYLE: italic">#include &lt;windowsx.h&gt;</span>将头文件<span style="FONT-STYLE: italic">&lt;windowsx.h&gt;</span>包含到你.C/.CPP文件中。<br /><br /></font></span></span></span></span><span style="COLOR: rgb(255,153,0)"><font face="Times New Roman">快速浏览消息分流器Wizard特性<br /><br /></font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">让我们开始吧。假设你已经编写了你的</font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman"> WinMain </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">的基本代码：已经成功填充了 </font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman">WNDCLASS </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">结构，注册了窗口类，并且编写了消息循环。现在你需要一个为你主函数编写<br />的消息处理函数。<br /><br />打开消息分流器Wizard。我们需要为我们的窗口选择消息，因为MCW需要用它来生成我们的消息处理函数。如你所知，Windows程序非常常见的处理消息是</font><span style="COLOR: rgb(255,0,0)"><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman"> WM_CLOSE </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">和<br /></font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman">WM_DESTROY </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">和 </font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman">WM_CREATE </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">，所以让我们选择消息分流器处理这些消息来创建窗口函数。然后，我们创建窗口函数的主体消息处理函数。<br /><br />在列表框中选择</font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman"> WM_CLOSE </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">, </font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman">WM_DESTROY </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">和 </font><span style="COLOR: rgb(153,0,0)"><font face="Times New Roman">WM_CREATE </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">。因为此窗口是我们程序的主窗口，我们选用main做为窗口的ID。这个窗口ID表识了我们的窗口/对话框，并且<br />使分流宏和出理函数作为后缀。当然，你要使特定窗口的所有消息处理保持一致。观察下面的编辑框。它们显示<span style="COLOR: rgb(204,0,0)"> HANDLE_MSG <span style="COLOR: rgb(0,0,0)">分流宏和关联的消息处理函数的原型。</span></span></font></span></span></span></span></span></span><br /></span></span></span></span></span></span></span></span></span></span></span></span></span><font face="Times New Roman"><img title="MCW2" src="http://docs.google.com/File?id=dcjhdv5v_8f6dbxc" /><br /><br />但是，等一下......我们说我们需要一个准备好的窗口处理函数。所以单击“<span style="FONT-WEIGHT: bold">Make Window Procedure</span>”选定框，并且确认<span style="FONT-WEIGHT: bold">Window </span>单选按钮已经被选择了。现在<br />我们准备好了。要注意的是，对话框的工作也像这样，但是要改变处理函数为对话框类型。<br /><br />首先，我们需要我们源代码的窗口处理函数。点击“<span style="FONT-WEIGHT: bold">Copy Macro</span>”按钮（或者使用<span style="FONT-STYLE: italic">Ctrl-M</span>），最小化Wizard（或者把它放到一边），回到你的IDE并且从剪贴板粘贴<br />（<span style="FONT-STYLE: italic">Ctrl-V</span>）代码到你的窗口函数的位置。</font><span name="intelliTxt"><font face="Times New Roman">Voilá（阿根廷拉丁语，认识的通知下）！你可以得到像下面的代码： <br /></font></span><span name="intelliTxt"><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: #008000"><font face="Times New Roman">//</font></span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008000"><font face="Times New Roman">//</font></span><span style="COLOR: #008000"><font face="Times New Roman"> main  Window Procedure<br /></font></span><span style="COLOR: #008000"><font face="Times New Roman">//<br /></font></span><font face="Times New Roman"><span style="COLOR: #000000">LRESULT CALLBACK main_WndProc (HWND hwnd, UINT msg, WPARAM wParam,   LPARAM lParam)<br />{<br />  </span><span style="COLOR: #0000ff">switch</span></font><font face="Times New Roman"><span style="COLOR: #000000">(msg)<br />  {<br />    HANDLE_MSG (hwnd, WM_CLOSE, main_OnClose);<br />    HANDLE_MSG (hwnd, WM_CREATE, main_OnCreate);<br />    HANDLE_MSG (hwnd, WM_DESTROY, main_OnDestroy);<br />      </span><span style="COLOR: #808080">///</span><span style="COLOR: #008000">/ TODO: Add window message crackers here<img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #808080"><br /></span><font face="Times New Roman"><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">: </span><span style="COLOR: #0000ff">return</span></font><span style="COLOR: #000000"><font face="Times New Roman"> DefWindowProc (hwnd, msg, wParam, lParam);<br />  }<br />}</font></span></div><br /></span><br /><font face="Times New Roman"> 这个窗口处理函数以三个消息分流宏展开工作！并且，通过TODO注释提示你记得必须在这里添加消息分流器宏。当你只是要添加一个</font><span style="COLOR: rgb(204,0,0)"><font face="Times New Roman"> HANDLE_MSG </font><span style="COLOR: rgb(0,0,0)"><font face="Times New Roman">宏到窗口函数中时，<br />记得取消“<span style="FONT-WEIGHT: bold">Mke Window Procedure</span>”选定框的选择。</font></span></span><br /><br /><font face="Times New Roman">但是这些代码现在还什么都做不了，因为我们还需要添加三个我们需要的消息处理函数。回到消息分流器Wizard工具的界面，并且单击“<span style="FONT-WEIGHT: bold">Copy Function</span>”按钮。切<br />换到你的代码，用鼠标定位到你需要函数主体插入的位置，然后用Ctrl+V或者菜单Edit/Paste粘贴。Wizard自动生成函数，使用 <span style="FONT-WEIGHT: bold">main</span> 标识窗口ID，并修正参数类型<br />使之符合<span style="FONT-STYLE: italic"> WINDOWSX.H </span>头文件的宏:<br /><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"><span style="COLOR: #008000"><font face="Times New Roman">//</font></span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008000"><font face="Times New Roman">//</font></span><span style="COLOR: #008000"><font face="Times New Roman">Process WM_CLOSE message for window/dialog: main<br /></font></span><font face="Times New Roman"><span style="COLOR: #008000">//<br /></span><span style="COLOR: #0000ff">void</span></font><font face="Times New Roman"><span style="COLOR: #000000"> main_OnClose(HWND hwnd)<br />{<br />  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: Add your message processing code here<img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #008000"><br /></span><font face="Times New Roman"><span style="COLOR: #000000">}<br /></span><span style="COLOR: #008000">//</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #008000"><font face="Times New Roman">//</font></span><span style="COLOR: #008000"><font face="Times New Roman">  Process WM_CREATE message for window/dialog: main<br /></font></span><span style="COLOR: #008000"><font face="Times New Roman">//<br /></font></span><font face="Times New Roman"><span style="COLOR: #000000">BOOL main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)<br />{<br />  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: Add your message processing code here<img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #008000"><br /></span><font face="Times New Roman"><span style="COLOR: #000000">}<br /></span><span style="COLOR: #008000">//</span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #008000"><font face="Times New Roman">//</font></span><span style="COLOR: #008000"><font face="Times New Roman">  Process WM_DESTROY message for window/dialog: main<br /></font></span><font face="Times New Roman"><span style="COLOR: #008000">//<br /></span><span style="COLOR: #0000ff">void</span></font><font face="Times New Roman"><span style="COLOR: #000000"> main_OnDestroy(HWND hwnd)<br />{<br />  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: Add your message processing code here<img src="http://www.cppblog.com/images/dot.gif" /></span></font><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><font face="Times New Roman">}</font></span></div><br /><font face="Times New Roman"><br /><br /></font><span name="intelliTxt"><br /></span><font face="Times New Roman">Wizard还可以自动生成开头注释，和TODO行以提醒你添加代码。现在你可以添加消息处理了，可以是简单的处理处理逻辑，或者复杂窗口函数。你也可以通过选定框移除<br />注释。<br /><br /></font><span style="COLOR: rgb(255,102,0)"><font face="Times New Roman">更多的消息分流器Wizard特性<br /></font><span style="COLOR: rgb(0,0,0)"><br /><font face="Times New Roman"><span style="FONT-WEIGHT: bold">消息过滤</span><br /><br />你可以过滤你暂时不打算处理的消息。单击“<span style="FONT-WEIGHT: bold">Filters..</span>”按钮（或者Ctrl+L），你会打开下面对话框。列表的消息按类型分类（分类标准来自Microsoft Spy++的效果），<br />你可以取消选定你不处理的消息。<br /></font></span></span><font face="Times New Roman"><img title="filter" src="http://docs.google.com/File?id=dcjhdv5v_9hn54g2" /><br /><br /></font><font face="Times New Roman"><span style="FONT-STYLE: italic">要注意的是在 v2.0 当前的问题是，当你打开消息过滤对话框时所有类型的消息都是选定的，当你点击OK，之前选定的消息会丢失（这并不意味着你粘贴到目标代码的<br />内容会消失）。<br /></span><br /><br /></font><span style="COLOR: rgb(255,102,0)"><span style="COLOR: rgb(0,0,0)"><br /><font face="Times New Roman"><span style="FONT-WEIGHT: bold">简洁窗口模式</span><br /><br />你可能需要减小消息分流Wizard窗体的大小。这可以通过取消菜单 <span style="FONT-WEIGHT: bold">View </span>的 “<span style="FONT-WEIGHT: bold">Show Target Code</span>”选项的选定（或者使用Ctrl+F11）。主窗口会取消目标代码区域：<br /><br /></font><font face="Times New Roman"><span style="FONT-WEIGHT: bold">窗体透明，取消注释和置顶<br /><br /></span>（译注：Sorry，暂不做翻译了，你可以通过尝试菜单 <span style="FONT-WEIGHT: bold">View</span> 的其它几个选项自己体会^_^）<br /><br /><br /></font><span style="COLOR: rgb(255,102,0)"><br /><font face="Times New Roman">未来特性<br /><br /><span style="COLOR: rgb(0,0,0)">下面的特性会在下一次发布时实现：</span><br /></font></span></span></span></pre></span><ul><li>帮助文件。 
</li><li>所有消息分流的参数和消息的完整帮助。 
</li><li>支持WTL！:) 
</li><li>窗口ID和配置保存（这个会在下一个2.x版本实现）。 
</li><li>项目配置和“消息映射”（a la MFC）（译注：好像是西班牙语，不认识:P）（这个也会在之后的2.5版本实现）。<br /></li></ul><span style="COLOR: rgb(255,102,0)"><span style="COLOR: rgb(0,0,0)"><br /><span style="COLOR: rgb(255,102,0)">快乐的编程！<br /><br /><span style="COLOR: rgb(0,0,0)">我希望这个小工具可以让每个 Windows SDK 程序员感兴趣，并且干净的编写 Win32 API 程序。我乐于接受改进这个工具的主意。如果你发现这个程序很好用，请给我发邮件，因为我非常高兴听到任何好的意见。<br /><br />谢谢所有支持！！You know who you are！（译注：不太明白这个要表达什么意思，“你知道你是谁！”乎？）<br /><br />任何时候，打开我的主页，你可以在那里找到这个程序的最新更新。<br /><br /><span style="COLOR: rgb(255,102,0)">历史：<br /><span style="COLOR: rgb(0,0,0)">  略...<br /><br /><span style="COLOR: rgb(255,102,0)">关于作者：</span></span></span></span></span></span></span><font style="COLOR: rgb(255,102,0)" size="2">Hernán Di Pietro<br /></font><img src="http://docs.google.com/File?id=dcjhdv5v_138hstzg" align="left" /><br /><font style="COLOR: rgb(255,102,0)" size="2"><span style="COLOR: rgb(0,0,0)">业余程序员。<br /><br />开始于1986年，在Commodore 64上编写BASIC程序。<br />在1990年第一台 8086 PC 上开始编写 QB 4.x。<br />1995-1996年转移到Visual Basic。<br />2002年，23岁时开始编写C++程序，并对 Windows API 上瘾。<br /><br />主页： http://usuarios.lycos.es/hernando<br /></span><br /></font><span style="COLOR: rgb(255,102,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(255,102,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(255,102,0)"><span style="COLOR: rgb(0,0,0)"></span></span></span></span></span></span><span name="intelliTxt"><pre><font face="Times New Roman"><br /></font></pre></span><span name="intelliTxt"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br /></span><span style="COLOR: rgb(255,153,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"><span style="COLOR: rgb(204,0,0)"><span style="COLOR: rgb(0,0,0)"></span></span></span></span></span></span></span></span><span style="COLOR: rgb(0,0,0)"></span></span></span></span></span></span></span><img src ="http://www.cppblog.com/nj-blog/aggbug/14559.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-11-02 00:00 <a href="http://www.cppblog.com/nj-blog/archive/2006/11/02/14559.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ACM初体验</title><link>http://www.cppblog.com/nj-blog/archive/2006/09/20/12771.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Wed, 20 Sep 2006 15:18:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/09/20/12771.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/12771.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/09/20/12771.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/12771.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/12771.html</trackback:ping><description><![CDATA[    这是我第一此参加ACM竞赛，我想也是最后一次了。呵呵，要毕业啦^_^<br />    8月28日接到赵欣苹的电话，说是有一个编程比赛要组队参加，邀请我加入她的队伍里。<a target="" class="" title="" href="/nj-blog/gallery/image/1211.html"><img alt="" src="http://www.cppblog.com/images/cppblog_com/nj-blog/2644/t_acm5.JPG" align="" border="" height="90" hspace="0" vspace="0" width="120" /></a><br />    因为不考研，开学比较闲（其实我一向是个闲人啦^_^），所以不假思索就答应了。<br />三天后去系主任李老师那里报名，这才第一次见到听闻已久的另一个队友：秦海龙<a target="" class="" title="" href="/nj-blog/gallery/image/1212.html"><img alt="" src="http://www.cppblog.com/images/cppblog_com/nj-blog/2644/t_acm6.JPG" align="" border="" height="90" hspace="0" vspace="0" width="120" /></a><br />    报完名才知道原来比赛是ACM啊！<br />    9月10号预赛，勉强通过。16号在哈工程的体育馆里决赛，做出了5道题。大概组委会念在是黑龙江省的第一次区域性竞赛，AC了5道题的全给了三等奖，一共有32个。呵呵，特价甩卖了。最多的也只AC出7道题，这些是一等奖，7支队伍。6道题的是二等奖，6支队伍。<br /><a target="" class="" title="" href="/nj-blog/gallery/image/1207.html"><img alt="" src="http://www.cppblog.com/images/cppblog_com/nj-blog/2644/t_acm1.JPG" align="" border="" height="90" hspace="0" vspace="0" width="120" /></a><a target="" class="" title="" href="/nj-blog/gallery/image/1210.html"><img alt="" src="http://www.cppblog.com/images/cppblog_com/nj-blog/2644/t_acm3.JPG" align="" border="" height="90" hspace="0" vspace="0" width="120" /><img alt="" src="http://www.cppblog.com/images/cppblog_com/nj-blog/2644/t_acm7.JPG" align="" border="" height="90" hspace="0" vspace="0" width="120" /><img alt="" src="http://www.cppblog.com/images/cppblog_com/nj-blog/2644/t_acm4.JPG" align="" border="" height="90" hspace="0" vspace="0" width="120" /></a><br />    从接到欣苹的通知那天到决赛，我只准备了19天，感觉很仓促。如果上天能给我再来一次的机会的话......<br />    不说废话了，还是十分高兴可以有这样一次机会和这么多高水平的人同场竞技，让我认识到自己在程序之路上原来还只是个井底之蛙。要学习的东西还是很多，努力！加油！<br />    而且意外收获了一个三等奖，哈哈^_^<br /><img src="http://www.cppblog.com/images/cppblog_com/nj-blog/2644/r_acm2.JPG" /><br /><br /><img src ="http://www.cppblog.com/nj-blog/aggbug/12771.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-09-20 23:18 <a href="http://www.cppblog.com/nj-blog/archive/2006/09/20/12771.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Boost/utility里有些什么?(2)</title><link>http://www.cppblog.com/nj-blog/archive/2006/08/16/11264.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Tue, 15 Aug 2006 16:24:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/08/16/11264.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/11264.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/08/16/11264.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/11264.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/11264.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal">
				<span lang="EN-US">2.<strong></strong></span>
				<strong>
						<span style="font-weight: normal; font-family: 宋体;">函数模板</span>
						<span lang="EN-US">checked_delete() </span>
				</strong>
				<strong>
						<span style="font-weight: normal; font-family: 宋体;">和</span>
						<font color="#000000">
								<span lang="EN-US">checked_array_delete()</span>
						</font>
				</strong>
				<strong>
						<span style="font-weight: normal;" lang="EN-US">
								<o:p>
								</o:p>
						</span>
				</strong>
		</p>
		<p class="MsoNormal">
				<strong>
						<span lang="EN-US">&lt;boost/checked_delete.hpp&gt;</span>
				</strong>
				<strong>
						<span style="font-weight: normal; font-family: 宋体;">定义了两个函数模板</span>
						<span lang="EN-US">checked_delete</span>
				</strong>
				<span lang="EN-US">
				</span>
				<span style="font-family: 宋体;">和</span>
				<strong>
						<span lang="EN-US">checked_array_delete</span>
				</strong>
				<strong>
						<span style="font-family: 宋体;">，</span>
				</strong>
				<strong>
						<span style="font-weight: normal; font-family: 宋体;">还有两个类模板</span>
						<span lang="EN-US">checked_deleter</span>
				</strong>
				<span lang="EN-US">
				</span>
				<span style="font-family: 宋体;">和</span>
				<strong>
						<span lang="EN-US">checked_array_deleter。</span>
				</strong>
		</p>
		<p class="MsoNormal">
				<span style="font-family: 宋体;">当我们利用指针删除一个对象的时候，对象类型是否完整决定了对象是否能够被正确删除。但是，如果你用</span>
				<span style="font-size: 13.5pt;">
				</span>
				<span style="font-family: 'Lucida Console';" lang="EN-US">delete</span>
				<span style="font-size: 13.5pt;" lang="EN-US">
				</span>
				<span style="font-family: 宋体;">去删除一个类型并不完整的对象的指针，编译器并不会给你提供任何错误信息（好吧，有些编译器会给出警告信息，但是程序员通常会忽略警告信息），但是这样做的结果却是对象的析构函数根本就没有被调用。</span>
				<span style="font-size: 13.5pt;">
						<u1:p>
						</u1:p>
				</span>
				<span style="font-size: 12pt; font-family: 宋体;" lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="font-family: 宋体;">所以，我们应当使用更严厉的手段禁止这种事情的发生。比如说使用</span>
				<span style="font-size: 13.5pt;">
				</span>
				<b>
						<span lang="EN-US">checked_delete</span>
				</b>
				<b>
						<span style="font-size: 13.5pt;" lang="EN-US">
						</span>
				</b>
				<span style="font-family: 宋体;">代替</span>
				<span style="font-size: 13.5pt;">
				</span>
				<b>
						<span lang="EN-US">delete</span>
				</b>
				<b>
						<span style="font-size: 13.5pt;" lang="EN-US">
						</span>
				</b>
				<span style="font-family: 宋体;">来删除指针。当指针所指向的是一个不完全类型时，</span>
				<span style="font-size: 13.5pt;">
				</span>
				<b>
						<span lang="EN-US">
						</span>
				</b>
				<span style="font-family: 宋体;">
				</span>
				<span style="font-size: 13.5pt;">
				</span>
				<b>
						<span lang="EN-US">checked_delete</span>
				</b>
				<b>
						<span style="font-size: 13.5pt;" lang="EN-US">
						</span>
				</b>
				<span style="font-family: 宋体;">
				</span>
				<span style="font-family: 宋体;">会使编译器发出错误信息。</span>
				<span lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<b>
						<font size="3">
								<span style="color: rgb(0, 0, 255);">class</span>
								<span style="color: rgb(0, 0, 0);"> test；</span>
								<span style="color: rgb(0, 128, 0);">//</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 128, 0);">有声明，但是忘记了定义，或是忘记    <br />          </span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">包含定义文件，test是一个不完全类型</span>
								<span style="color: rgb(0, 128, 0);">
								</span>
						</font>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<font size="3">main()<br />{<br />test </font>
						</span>
						<font size="3">
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> pt </span>
								<span style="color: rgb(0, 0, 0);">=</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 0, 0);"> NULL;<br />delete pt;  </span>
								<span style="color: rgb(0, 128, 0);">//</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 128, 0);"> 有时会有警告信息，<br />            </span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);">但有时什么都没有。</span>
						</font>
						<span style="color: rgb(0, 128, 0);">
								<br />
						</span>
						<font size="3">
								<span style="color: rgb(0, 0, 0);">checked_delete(pt); </span>
								<span style="color: rgb(0, 128, 0);">//</span>
								<span style="color: rgb(0, 128, 0);"> 发出错误信息。</span>
						</font>
						<span style="color: rgb(0, 128, 0);">
								<br />
						</span>
				</b>
				<span style="color: rgb(0, 0, 0);">
						<font size="3">
								<b>}</b>
								<br />
						</font>
				</span>
		</div>
		<p class="MsoNormal">
				<b>
						<span lang="EN-US">checked_array_delete</span>
				</b>
				<span style="font-family: 宋体;">是用来对应于</span>
				<b>
						<span lang="EN-US">delete [ ] operator</span>
				</b>
				<span style="font-family: 宋体;">，</span>
				<b>
						<span lang="EN-US">checked_deleter</span>
				</b>
				<span style="font-family: 宋体;">和</span>
				<b>
						<span lang="EN-US">checked_array_deleter</span>
				</b>
				<span style="font-family: 宋体;">是可以配接的仿函数版本。</span>
		</p>
		<p class="MsoNormal">
				<span lang="EN-US">3.</span>
				<span style="font-family: 宋体;">函数模板</span>
				<b>
						<span lang="EN-US">next()</span>
				</b>
				<span style="font-family: 宋体;">和</span>
				<b>
						<span lang="EN-US">prior() <o:p></o:p></span>
				</b>
				<br />
				<span style="font-family: 宋体;">包括</span>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<b>
						<font size="3">
								<span style="color: rgb(0, 0, 0);">template </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 255);">class</span>
								<span style="color: rgb(0, 0, 0);">T</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 0, 0);">T next(T x);<br />template </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 255);">class</span>
								<span style="color: rgb(0, 0, 0);">T, </span>
								<span style="color: rgb(0, 0, 255);">class</span>
								<span style="color: rgb(0, 0, 0);"> Distance</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 0, 0);">T next(T x, Distance n);<br />template </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 255);">class</span>
								<span style="color: rgb(0, 0, 0);">T</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 0, 0);">T prior(T x);<br />template </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 255);">class</span>
								<span style="color: rgb(0, 0, 0);">T, </span>
								<span style="color: rgb(0, 0, 255);">class</span>
								<span style="color: rgb(0, 0, 0);"> Distance</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
						</font>
				</b>
				<span style="color: rgb(0, 0, 0);">
						<font size="3">
								<b>T prior(T x, Distance n);</b>
								<br />
						</font>
				</span>
		</div>
		<b>
				<span lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</b>
		<p class="MsoNormal">
				<span style="font-family: 宋体;">函数模板对传入的指针，智能指针或是迭代器做递增或递减，并传回它。用法如下：</span>
				<b>
						<span lang="EN-US">
						</span>
				</b>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<font size="3">
						<span style="color: rgb(0, 0, 255);">const</span>
						<span style="color: rgb(0, 0, 0);"> std::list</span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">T</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">::iterator p </span>
						<span style="color: rgb(0, 0, 0);">=</span>
				</font>
				<font size="3">
						<span style="color: rgb(0, 0, 0);"> get_some_iterator();<br /></span>
						<span style="color: rgb(0, 0, 255);">const</span>
						<span style="color: rgb(0, 0, 0);"> std::list</span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">T</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">::iterator prev </span>
						<span style="color: rgb(0, 0, 0);">=</span>
				</font>
				<font size="3">
						<span style="color: rgb(0, 0, 0);"> boost::prior(p);<br /></span>
						<span style="color: rgb(0, 0, 255);">const</span>
						<span style="color: rgb(0, 0, 0);"> std::list</span>
						<span style="color: rgb(0, 0, 0);">&lt;</span>
						<span style="color: rgb(0, 0, 0);">T</span>
						<span style="color: rgb(0, 0, 0);">&gt;</span>
						<span style="color: rgb(0, 0, 0);">::iterator next </span>
						<span style="color: rgb(0, 0, 0);">=</span>
						<span style="color: rgb(0, 0, 0);"> boost::next(prev, </span>
						<span style="color: rgb(0, 0, 0);">2</span>
						<span style="color: rgb(0, 0, 0);">);</span>
				</font>
		</div>
		<p>
		</p>
		<p class="MsoNormal">
				<span style="font-family: 宋体;">事实上，</span>
				<b>
						<span lang="EN-US">T next(T x)</span>
				</b>
				<b>
						<span style="font-family: 宋体;">和</span>
						<span lang="EN-US">T prior(T x)</span>
				</b>
				<span style="font-family: 宋体;">将分别调用</span>
				<b>
						<span lang="EN-US">operator++</span>
				</b>
				<b>
						<span style="font-family: 宋体;">和</span>
						<span lang="EN-US">operator--</span>
				</b>
				<span style="font-family: 宋体;">，而</span>
				<b>
						<span lang="EN-US">T next(T x, Distance n)</span>
				</b>
				<span style="font-family: 宋体;">和</span>
				<b>
						<span lang="EN-US">T prior(T x, Distance n)</span>
				</b>
				<span style="font-family: 宋体;">则调用</span>
				<b>
						<span lang="EN-US">std::distance(T x, size_t n) </span>
				</b>
				<span lang="EN-US">。 </span>
		</p>
		<p class="MsoNormal">
				<span lang="EN-US">4.<b>noncopyable</b></span>
				<span style="font-family: 宋体;">类</span>
		</p>
		<p class="MsoNormal">
				<span style="font-family: 宋体;">如果你需要设计一个不可以被复制的类，那么你就要明确地将它的拷贝构造函数和</span>
				<span lang="EN-US">operator = ()</span>
				<span style="font-family: 宋体;">放到</span>
				<span lang="EN-US">private</span>
				<span style="font-family: 宋体;">声明下面。</span>
				<span lang="EN-US">Boos\utility</span>
				<span style="font-family: 宋体;">准备了一个基类</span>
				<span lang="EN-US">noncopyable</span>
				<span style="font-family: 宋体;">，你只需要让你的类继承自</span>
				<span lang="EN-US">noncopyable</span>
				<span style="font-family: 宋体;">就可以获得这个性质。对你的类来说这也是一个显式的声明：“我是不可以被复制的！”</span>
				<br />
				<span style="font-family: 宋体;">用法：</span>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<b>
						<font size="3">
								<span style="color: rgb(0, 0, 0);">#include </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);">boost</span>
								<span style="color: rgb(0, 0, 0);">/</span>
								<span style="color: rgb(0, 0, 0);">utility.hpp</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
						</font>
						<span style="color: rgb(0, 0, 0);">
								<br />
								<br />
						</span>
						<font size="3">
								<span style="color: rgb(0, 0, 255);">class</span>
						</font>
				</b>
				<font size="3">
						<span style="color: rgb(0, 0, 0);">
								<b> ResourceLadenFileSystem : boost::noncopyable {<br /><img src="http://www.cppblog.com/images/dot.gif" /></b>
						</span>
						<br />
				</font>
		</div>
		<br />
		<p class="MsoNormal">
				<span lang="EN-US">
				</span>
		</p>
		<p class="MsoNormal">
				<span lang="EN-US">5</span>
				<span style="font-family: 宋体;">．函数模板</span>
				<b>
						<span lang="EN-US">addressof()<o:p></o:p></span>
				</b>
		</p>
		<p class="MsoNormal">
				<span style="font-family: 宋体;">函数模板返回一个对象的真实地址（当然这是交给指针了）：</span>
		</p>
		<b>
				<span lang="EN-US">
				</span>
		</b>
		<b>
				<span lang="EN-US">
						<o:p>
						</o:p>
				</span>
		</b>
		<p class="MsoNormal">
				<span style="font-family: 宋体;">
				</span>
		</p>
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<b>
						<font size="3">
								<span style="color: rgb(0, 0, 0);">template </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);">typename T</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);">inline T</span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);">                addressof(T</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 0, 0);"> v);<br />template </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);">typename T</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);">inline </span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> T</span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);">         addressof(</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);"> T</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 0, 0);"> v);<br />template </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);">typename T</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);">inline </span>
								<span style="color: rgb(0, 0, 255);">volatile</span>
								<span style="color: rgb(0, 0, 0);"> T</span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);">      addressof(</span>
								<span style="color: rgb(0, 0, 255);">volatile</span>
								<span style="color: rgb(0, 0, 0);"> T</span>
								<span style="color: rgb(0, 0, 0);">&amp;</span>
						</font>
						<font size="3">
								<span style="color: rgb(0, 0, 0);"> v);<br />template </span>
								<span style="color: rgb(0, 0, 0);">&lt;</span>
								<span style="color: rgb(0, 0, 0);">typename T</span>
								<span style="color: rgb(0, 0, 0);">&gt;</span>
								<span style="color: rgb(0, 0, 0);">inline </span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);">
								</span>
								<span style="color: rgb(0, 0, 255);">volatile</span>
								<span style="color: rgb(0, 0, 0);">T</span>
								<span style="color: rgb(0, 0, 0);">*</span>
								<span style="color: rgb(0, 0, 0);"> addressof(</span>
								<span style="color: rgb(0, 0, 255);">const</span>
								<span style="color: rgb(0, 0, 0);">
								</span>
								<span style="color: rgb(0, 0, 255);">volatile</span>
								<span style="color: rgb(0, 0, 0);">T</span>
								<span style="color: rgb(0, 0, 0);">
								</span>
								<span style="color: rgb(0, 0, 0);">&amp; v);</span>
						</font>
				</b>
		</div>
		<br />我知道你想说，为什么不是简单的调用<b><span lang="EN-US">operator&amp;()</span></b><span style="font-family: 宋体;">。因为</span><span lang="EN-US">c++</span><span style="font-family: 宋体;">允许重载</span><b><span lang="EN-US">operator&amp;()</span></b><span style="font-family: 宋体;">，所以有时使用它获得的并不是对象的真实地址，而是编写重载</span><b><span lang="EN-US">operator&amp;()</span></b><span style="font-family: 宋体;">代码的作者希望给你的那个。如果你却是希望获得的是这个对象的地址，使用</span><b><span lang="EN-US">addressof():<o:p></o:p></span></b><p></p><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><b><font size="3"><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">boost</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">utility.hpp</span><span style="color: rgb(0, 0, 0);">&gt;</span></font><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);"><font size="3">struct</font></span><font size="3"><span style="color: rgb(0, 0, 0);"> useless_type {};<br /><br /></span><span style="color: rgb(0, 0, 255);">class</span></font><font size="3"><span style="color: rgb(0, 0, 0);"> nonaddressable {<br />  useless_type </span><span style="color: rgb(0, 0, 255);">operator</span><span style="color: rgb(0, 0, 0);">&amp;</span><span style="color: rgb(0, 0, 0);">() </span><span style="color: rgb(0, 0, 255);">const</span></font><font size="3"><span style="color: rgb(0, 0, 0);">;<br />};<br /><br /></span><span style="color: rgb(0, 0, 255);">void</span></font><font size="3"><span style="color: rgb(0, 0, 0);"> f() {<br />  nonaddressable x;<br />  nonaddressable</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> xp </span><span style="color: rgb(0, 0, 0);">=</span></font><font size="3"><span style="color: rgb(0, 0, 0);"> boost::addressof(x);<br />  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> nonaddressable* xpe = &amp;x; </span><span style="color: rgb(0, 128, 0);">//</span></font><font size="3"><span style="color: rgb(0, 128, 0);">error! operator&amp;()已经被重载，<br />                              </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">它返回的是useless_type的指针</span><br />}<span style="color: rgb(0, 128, 0);"></span></font></b><br /></div><br /><br /><br />上述的所有东西都可以简单的通过在你的源文件开头处写上：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><b><font size="3"><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">boost\utility.hpp</span><span style="color: rgb(0, 0, 0);">&gt;</span></font><span style="color: rgb(0, 0, 0);"><br /></span><font size="3"><span style="color: rgb(0, 0, 255);">using</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">namespace</span><span style="color: rgb(0, 0, 0);"> boost;</span></font></b></div>就可以使用了。当然我是指你机器上已经有boost这个奇妙的库，并且正确配置^_^<img src ="http://www.cppblog.com/nj-blog/aggbug/11264.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-08-16 00:24 <a href="http://www.cppblog.com/nj-blog/archive/2006/08/16/11264.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Boost/utility里有什么东西？(1)</title><link>http://www.cppblog.com/nj-blog/archive/2006/08/11/11144.html</link><dc:creator>小山日志</dc:creator><author>小山日志</author><pubDate>Fri, 11 Aug 2006 15:59:00 GMT</pubDate><guid>http://www.cppblog.com/nj-blog/archive/2006/08/11/11144.html</guid><wfw:comment>http://www.cppblog.com/nj-blog/comments/11144.html</wfw:comment><comments>http://www.cppblog.com/nj-blog/archive/2006/08/11/11144.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/nj-blog/comments/commentRss/11144.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/nj-blog/services/trackbacks/11144.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal">
				<span style="FONT-FAMILY: 宋体">和</span>
				<span lang="EN-US">STL</span>
				<span style="FONT-FAMILY: 宋体">的</span>
				<span lang="EN-US">utility</span>
				<span style="FONT-FAMILY: 宋体">一样，</span>
				<span lang="EN-US">boost/utility</span>
				<span style="FONT-FAMILY: 宋体">里包含了一些实用的小工具。</span>
		</p>
		<p class="MsoNormal">
				<span lang="EN-US">
						<?xml:namespace prefix = o /?>
						<o:p>
						</o:p>
				</span>
		</p>
		<p class="MsoNormal">
				<span style="FONT-FAMILY: 宋体">首先是</span>
				<span lang="EN-US">
						<span>  </span>Base-from-Member</span>
				<span style="FONT-FAMILY: 宋体">：</span>
		</p>
		<p class="MsoNormal">
				<span style="FONT-FAMILY: 宋体">有时你可能需要依赖成员变量来初始化基类，像这样：</span>
		</p>
		<div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="COLOR: rgb(0,0,255)">class</span>
				<span style="COLOR: rgb(0,0,0)"> fdoutbuf<br />    : </span>
				<span style="COLOR: rgb(0,0,255)">public</span>
				<span style="COLOR: rgb(0,0,0)"> std::streambuf<br />{<br /></span>
				<span style="COLOR: rgb(0,0,255)">public</span>
				<span style="COLOR: rgb(0,0,0)">:<br />    </span>
				<span style="COLOR: rgb(0,0,255)">explicit</span>
				<span style="COLOR: rgb(0,0,0)"> fdoutbuf( </span>
				<span style="COLOR: rgb(0,0,255)">int</span>
				<span style="COLOR: rgb(0,0,0)"> fd );<br />    </span>
				<span style="COLOR: rgb(0,128,0)">//</span>
				<span style="COLOR: rgb(0,128,0)">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span style="COLOR: rgb(0,128,0)">
				</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />};<br /><br /></span>
				<span style="COLOR: rgb(0,0,255)">class</span>
				<span style="COLOR: rgb(0,0,0)"> fdostream<br />    : </span>
				<span style="COLOR: rgb(0,0,255)">public</span>
				<span style="COLOR: rgb(0,0,0)"> std::ostream<br />{<br /></span>
				<span style="COLOR: rgb(0,0,255)">protected</span>
				<span style="COLOR: rgb(0,0,0)">:<br />    fdoutbuf buf;<br /></span>
				<span style="COLOR: rgb(0,0,255)">public</span>
				<span style="COLOR: rgb(0,0,0)">:<br />    </span>
				<span style="COLOR: rgb(0,0,255)">explicit</span>
				<span style="COLOR: rgb(0,0,0)"> fdostream( </span>
				<span style="COLOR: rgb(0,0,255)">int</span>
				<span style="COLOR: rgb(0,0,0)"> fd )<br />        : buf( fd ), std::ostream( </span>
				<span style="COLOR: rgb(0,0,0)">&amp;</span>
				<span style="COLOR: rgb(0,0,0)">buf )<br />        {}<br />    </span>
				<span style="COLOR: rgb(0,128,0)">//</span>
				<span style="COLOR: rgb(0,128,0)">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span style="COLOR: rgb(0,128,0)">
				</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />};<br /><br /></span>
		</div>
		<br />
		<p class="MsoNormal">
				<span style="FONT-FAMILY: 宋体">但是，这里</span>
				<span lang="EN-US">fdostream</span>
				<span style="FONT-FAMILY: 宋体">的构造函数的初始化是错误的，因为</span>
				<span lang="EN-US">c++</span>
				<span style="FONT-FAMILY: 宋体">语法要求基类的初始化要先于成员变量的初始化。</span>
				<span lang="EN-US">Base-from-Member</span>
				<span style="FONT-FAMILY: 宋体">提供的解决之道如下：</span>
		</p>
		<div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="COLOR: rgb(0,0,255)">class</span>
				<span style="COLOR: rgb(0,0,0)"> fdoutbuf<br />    : </span>
				<span style="COLOR: rgb(0,0,255)">public</span>
				<span style="COLOR: rgb(0,0,0)"> std::streambuf<br />{<br /></span>
				<span style="COLOR: rgb(0,0,255)">public</span>
				<span style="COLOR: rgb(0,0,0)">:<br />    </span>
				<span style="COLOR: rgb(0,0,255)">explicit</span>
				<span style="COLOR: rgb(0,0,0)"> fdoutbuf( </span>
				<span style="COLOR: rgb(0,0,255)">int</span>
				<span style="COLOR: rgb(0,0,0)"> fd );<br />    </span>
				<span style="COLOR: rgb(0,128,0)">//</span>
				<span style="COLOR: rgb(0,128,0)">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span style="COLOR: rgb(0,128,0)">
				</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />};<br /><br /></span>
				<span style="COLOR: rgb(0,0,255)">class</span>
				<span style="COLOR: rgb(0,0,0)"> fdostream<br />    : </span>
				<span style="COLOR: rgb(0,0,255)">private</span>
				<span style="COLOR: rgb(0,0,0)"> boost::base_from_member</span>
				<span style="COLOR: rgb(0,0,0)">&lt;</span>
				<span style="COLOR: rgb(0,0,0)">fdoutbuf</span>
				<span style="COLOR: rgb(0,0,0)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    , </span>
				<span style="COLOR: rgb(0,0,255)">public</span>
				<span style="COLOR: rgb(0,0,0)"> std::ostream<br />{<br />    </span>
				<span style="COLOR: rgb(0,128,0)">//</span>
				<span style="COLOR: rgb(0,128,0)"> Helper typedef's</span>
				<span style="COLOR: rgb(0,128,0)">
				</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    typedef boost::base_from_member</span>
				<span style="COLOR: rgb(0,0,0)">&lt;</span>
				<span style="COLOR: rgb(0,0,0)">fdoutbuf</span>
				<span style="COLOR: rgb(0,0,0)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">  pbase_type;<br />    typedef std::ostream                        base_type;<br /></span>
				<span style="COLOR: rgb(0,0,255)">public</span>
				<span style="COLOR: rgb(0,0,0)">:<br />    </span>
				<span style="COLOR: rgb(0,0,255)">explicit</span>
				<span style="COLOR: rgb(0,0,0)"> fdostream( </span>
				<span style="COLOR: rgb(0,0,255)">int</span>
				<span style="COLOR: rgb(0,0,0)"> fd )<br />        : pbase_type( fd ), base_type( </span>
				<span style="COLOR: rgb(0,0,0)">&amp;</span>
				<span style="COLOR: rgb(0,0,0)">member )<br />        {}<br />    </span>
				<span style="COLOR: rgb(0,128,0)">//</span>
				<span style="COLOR: rgb(0,128,0)">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span style="COLOR: rgb(0,128,0)">
				</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />};</span>
		</div>
		<span style="FONT-FAMILY: 宋体">
				<br />模板类</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: 黑体">template &lt; typename MemberType, int UniqueID = 0 &gt; <br />        class boost::base_from_member;</span>
		<span lang="EN-US">
				<o:p>
				</o:p>
		</span>
		<span style="FONT-FAMILY: 宋体">是一个外覆类（姑且这么叫了</span>
		<span lang="EN-US">^_^</span>
		<span style="FONT-FAMILY: 宋体">）。<br />如上，私有继承</span>
		<span lang="EN-US">base_from_member</span>
		<span style="FONT-FAMILY: 宋体">，原先的成员变量将做为</span>
		<span lang="EN-US">base_from_member</span>
		<span style="FONT-FAMILY: 宋体">的成员变量</span>
		<span lang="EN-US">member</span>
		<span style="FONT-FAMILY: 宋体">先于基类</span>
		<span lang="EN-US">base_type</span>
		<span style="FONT-FAMILY: 宋体">初始化，这样所需的依赖关系可以满足。事实上比这更好的是，</span>
		<span lang="EN-US">base_from_member</span>
		<span style="FONT-FAMILY: 宋体">的构造函数是模板函数，它可以有</span>
		<span lang="EN-US">0</span>
		<span style="FONT-FAMILY: 宋体">至</span>
		<span lang="EN-US">10</span>
		<span style="FONT-FAMILY: 宋体">个参数，参数类型可以各不相同。</span>
<img src ="http://www.cppblog.com/nj-blog/aggbug/11144.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/nj-blog/" target="_blank">小山日志</a> 2006-08-11 23:59 <a href="http://www.cppblog.com/nj-blog/archive/2006/08/11/11144.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>