??xml version="1.0" encoding="utf-8" standalone="yes"?>国产亚洲精品美女久久久,久久久久综合网久久,国产69精品久久久久9999APGFhttp://www.shnenglu.com/nj-blog/M,学习与思?zh-cnSat, 28 Jun 2025 22:11:24 GMTSat, 28 Jun 2025 22:11:24 GMT60l制牛顿法复杂边界分形图 && L扭Ӟhttp://www.shnenglu.com/nj-blog/archive/2006/12/31/17108.html山日志山日志Sun, 31 Dec 2006 15:58:00 GMThttp://www.shnenglu.com/nj-blog/archive/2006/12/31/17108.htmlhttp://www.shnenglu.com/nj-blog/comments/17108.htmlhttp://www.shnenglu.com/nj-blog/archive/2006/12/31/17108.html#Feedback3http://www.shnenglu.com/nj-blog/comments/commentRss/17108.htmlhttp://www.shnenglu.com/nj-blog/services/trackbacks/17108.html
谨以此图BS自己的懒惰行为!呵呵Q?月䆾的想法到现在才完成。还好没有拖?7q去^_^?br />先把囄和代码给出,明天再把文字补上?br />




山日志 2006-12-31 23:58 发表评论
]]>
UC~写的矩阵工具包http://www.shnenglu.com/nj-blog/archive/2006/12/07/16099.html山日志山日志Thu, 07 Dec 2006 09:06:00 GMThttp://www.shnenglu.com/nj-blog/archive/2006/12/07/16099.htmlhttp://www.shnenglu.com/nj-blog/comments/16099.htmlhttp://www.shnenglu.com/nj-blog/archive/2006/12/07/16099.html#Feedback4http://www.shnenglu.com/nj-blog/comments/commentRss/16099.htmlhttp://www.shnenglu.com/nj-blog/services/trackbacks/16099.html矩阵怹Q纯C~写?br />不能用C++q点让我十分郁闷啊^_^....
一共包含如下东西:
typedef struct _matrix2D matrix2D; //一个结构体cdmatrix2D

BOOL initMatrix(matrix2D
* pm, int h, int w); //初始化pm为h×w的零矩阵
void delMatrix(matrix2D* pm);  //矩阵的内部数据空间全部是动态分配的Q所以退Z前一定要删除矩阵
int getData(matrix2D* pm, int x, int y);  //q回矩阵pmQ坐标ؓx、y的元素?/span>
void setData(matrix2D* pm, int x,int y, int data);   //矩阵pmQ坐标ؓx、y的元素值置为data
void setMatrix(matrix2D* lhs, matrix2D* rhs);  //删除矩阵lhs原先的|q深层拷贝ؓrhs
matrix2D addMatrix(matrix2D* lhs, matrix2D* rhs);  //矩阵相加Q返回一个新的矩?/span>
matrix2D mulMatrix(matrix2D* lhs, matrix2D* rhs);  //矩阵怹Q返回一个新的矩?/span>
void printMatrix(matrix2D* pm);  //格式化打印矩阵pm

q是一个测试程序,单相乘两个矩阵:
#include "matrix2d.h"

int main()
{
    
int i,j;
    matrix2D  rhs;
    matrix2D  lhs;
    matrix2D  result;

    initMatrix(
&lhs, 1110);
    initMatrix(
&rhs, 102);

        
//lhs矩阵讄元素?/span>
    for(i = 0; i<11; i++){
        
for(j = 0; j<10; j++){
            setData(
&lhs, i, j, 1);
        }

    }

        
//rhs矩阵讄元素?/span>
    for(i = 0; i<10; i++){
        
for(j = 0; j<2; j++){
            setData(
&rhs, i, j, i+1);
        }

    }

        
//矩阵怹
    result = mulMatrix(&lhs, &rhs);
        
//打印三个矩阵
    printMatrix(&lhs);
    printMatrix(
&rhs);
    printMatrix(
&result);
        
//不用了,记得释放矩阵I间..
    delMatrix(&lhs);
    delMatrix(
&rhs);
    delMatrix(
&result);
}

q里是显C结果:

点击q里下蝲完整的源代码和运行程序?br />

山日志 2006-12-07 17:06 发表评论
]]>
逆L兰式转换成L兰式表达?/title><link>http://www.shnenglu.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.shnenglu.com/nj-blog/archive/2006/12/05/16011.html</guid><wfw:comment>http://www.shnenglu.com/nj-blog/comments/16011.html</wfw:comment><comments>http://www.shnenglu.com/nj-blog/archive/2006/12/05/16011.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/nj-blog/comments/commentRss/16011.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/nj-blog/services/trackbacks/16011.html</trackback:ping><description><![CDATA[    q是严蔚敏《数据结构》配套习题册上的题目Q将逆L兰式转换成L兰式Qƈ提示错误Q作为简化,只处?+-*/"?~9的数字)?br />    例如Q?123*-"转换成L兰式?-1*23"<br />    逆L兰式"123*-"的表辑ּ树如下:<br />    <img title="exp-tree" style="width: 206px; height: 166px;" src="http://docs.google.com/File?id=dddhs32p_4cztm4q" />所以这个{换过E就是:已知一个二叉树的后栚w历序列,求先栚w历序列?br />    我的法是根据后栚w历的序列构造一个表辑ּ树,q而先栚w历此树获得L兰式表达式?br />    定义了两个结构体Q?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);">&</span><span style="color: rgb(0, 0, 0);"> e):op(e.op), lhs(e.lhs), rhs(e.rhs) { }<br />};<br /></span></div><br />表示一个表辑ּQ也是表辑ּ树上的一个子树?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);"><</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">></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);">&</span><span style="color: rgb(0, 0, 0);"> i):number(i.number), pExp(i.pExp), isNumber(i.isNumber){ }<br />};<br /></span></div><p><br />表示一个节点,它可以是一个数字,或者一个表辑ּQpExpq里我用的?a >boost?/a>的智能指针shared_ptrQ所以编译的话,需要先安装boost库)?br />q行的结果如图:<br /><img src="http://www.shnenglu.com/images/cppblog_com/nj-blog/2767/r_print-porland.JPG" /><br />*输入Ӟ?e'表示输入l束?br />完整的代码和可执行文件点?a class="" title="" href="/Files/nj-blog/porland.rar" target="">q里</a>下蝲。权当抛砖引玉了Q希望有更好法的同学赐教?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.shnenglu.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.shnenglu.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.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 0);">#include </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">stack</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">algorithm</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 255);">string</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">iostream</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="color: rgb(0, 0, 0);"><</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);">></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_178_376_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    shared_ptr</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"> pExp;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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);">&</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.shnenglu.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.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_390_572_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item  lhs;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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);">&</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.shnenglu.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.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_587_712_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);">;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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);">&</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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_743_936_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span><span style="color: rgb(0, 0, 0);"><<</span><span style="color: rgb(0, 0, 0);"> exp.op ;<br /><img src="http://www.shnenglu.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);"><<</span><span style="color: rgb(0, 0, 0);"> exp.lhs.number;<br /><img src="http://www.shnenglu.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.shnenglu.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);"><<</span><span style="color: rgb(0, 0, 0);"> exp.rhs.number;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_950_2397_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    stack</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">Item</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">  ExpStack;<br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpItem;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpLhs;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    Item tmpRhs;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout</span><span style="color: rgb(0, 0, 0);"><<</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Input the Express(输入 'e'标识l束):</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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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);">>></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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_1194_1966_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_1320_1421_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_1511_1903_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">操作W每ơ要对应两个被操作数Q否则语法错?/span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.shnenglu.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);"><</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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">操作W两边的元素出栈</span><span style="color: rgb(0, 128, 0);"><br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.pop();<br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />                ExpStack.pop();<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.shnenglu.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.shnenglu.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);"><</span><span style="color: rgb(0, 0, 0);">Exp</span><span style="color: rgb(0, 0, 0);">></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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        ExpStack.pop();<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.shnenglu.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);"><<</span><span style="color: rgb(0, 0, 0);"> tmpItem.number </span><span style="color: rgb(0, 0, 0);"><<</span><span style="color: rgb(0, 0, 0);">endl;<br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </span><span style="color: rgb(0, 0, 0);"><<</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.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);">&</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.shnenglu.com/images/dot.gif" /></span><span id="Codehighlighter1_2199_2277_Open_Text"><span style="color: rgb(0, 0, 0);">{<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </span><span style="color: rgb(0, 0, 0);"><<</span><span style="color: rgb(0, 0, 0);"> e.what() </span><span style="color: rgb(0, 0, 0);"><<</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.shnenglu.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.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        cout </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);">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);"><<</span><span style="color: rgb(0, 0, 0);"> endl;<br /><img src="http://www.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />        cin </span><span style="color: rgb(0, 0, 0);">>></span><span style="color: rgb(0, 0, 0);"> tmpChar;<br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.shnenglu.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.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="color: rgb(0, 0, 0);"><br /><img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /></span></span></div><img src ="http://www.shnenglu.com/nj-blog/aggbug/16011.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/nj-blog/" target="_blank">山日志</a> 2006-12-05 14:45 <a href="http://www.shnenglu.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.shnenglu.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.shnenglu.com/nj-blog/archive/2006/11/05/14704.html</guid><wfw:comment>http://www.shnenglu.com/nj-blog/comments/14704.html</wfw:comment><comments>http://www.shnenglu.com/nj-blog/archive/2006/11/05/14704.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.shnenglu.com/nj-blog/comments/commentRss/14704.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/nj-blog/services/trackbacks/14704.html</trackback:ping><description><![CDATA[ <p>转自<a class="" title="" target=""><font color="#0000ff">Dreamer's Blog</font><br /></a><br />      今天在网上无意中发现了苹果电脑之父乔布斯在斯坦福大学的演Ԍ他在演讲中说了三个关于自q故事Q我看了之后很有感触。今天把原文和译文都发上来,供大家参考。另?a target="_blank" tip="">q里有YouTube上的视频</a>观看?a target="_blank" tip="">q里有演讲mp3下蝲?/a><br /><br />      Steve Jobs_你得扑և你爱?(You've got to find what you love.)。?br /><br />      以下是苹果计机公司与Pixar动画制作室执行长Steve Jobs?005q六?2日对全体史丹佛大学毕业生的演讲内容:<br /><br />      今天Q有荣幸来到各位从世界上最好的学校之一毕业的毕业典Cg。我从来没从大学毕业。说实话Q这是我d学毕业最q的一刅R今天,我只说三个故事,不谈大道理,三个故事好。?br /><br />      W一个故事,是关于h生中的点Ҏ滴怎么串连在一赗?br /><br />      我在里d学院QReed collegeQ待了六个月办休学了。到我退学前Q一׃学了十八个月。那么,我ؓ什么休学? <br /><br />      q得从我出生前讲赗我的亲生母亲当时是个研I生Q年L婚妈妈,她决定让别h收养我。她强烈觉得应该让有大学毕业的h收养我,所以我出生Ӟ她就准备让我被一对律师夫妇收充R但是这对夫d了最后一d悔了Q他们想收养奛_。所以在{待收养名单上的一对夫妻,我的ȝ母,在一天半夜里接到一通电话,问他们「有一名意外出生的男孩Q你们要认养他吗Q」而他们的回答是「当然要」。后来,我的生母发现Q我现在的妈妈从来没有大学毕业,我现在的爸爸则连高中毕业也没有。她拒绝在认L件上做最后签字。直到几个月后,我的ȝ母同意将来一定会让我上大学,Ҏ软化态度。?br /><br />      十七q后Q我上大学了。但是当时我无知选了一所学费几乎跟史丹佛一栯的大学,我那工h阶的父母所有积蓄都花在我的学费上。六个月后,我看不出念这个书的hg在。那时候,我不知道q辈子要q什么,也不知道念大学能Ҏ有什么帮助,而且我ؓ了念q个书,花光了我父母q辈子的所有积蓄,所以我军_休学Q相信船到桥头自然直。当时这个决定看来相当可怕,可是现在看来Q那是我q辈子做q最好的军_之一。当我休学之后,我再也不用上我没兴趣的必修课Q把旉拿去听那些我有兴的课。?br /><br />      q一点也不浪漫。我没有宿舍Q所以我睡在友h安的地板上Q靠着回收可乐I罐的五先o退费买吃的Q每个星期天晚上得走七里的\l过大半个镇d度教的Hare Krishna庙吃顿好料。我喜欢Hare Krishna庙的好料。追L的好奇与直觉Q我所驻的大部分事物Q后来看来都成了无h之宝。D例来_ <br /><br />      当时里d学院有着大概是全国最好的书法指导。在整个校园内的每一张v报上Q每个抽屉的标签上,都是丽的手写字。因为我休学了,可以不照正常选课E序来,所以我跑去学书法。我学了serif与san serif字体Q学到在不同字母l合间变更字间距Q学到活版印刷伟大的地方。书法的好、历史感与艺术感是科学所无法捕捉的,我觉得那很迷人。?br /><br />      我没预期q学的这些东西能在我生活中v些什么实际作用,不过十年后,当我在设计第一台麦金塔Ӟ我想起了当时所学的东西Q所以把q些东西都设计进了麦金塔里,q是W一台能印刷出漂亮东西的计算机。如果我没沉Z那样一门课里,麦金塔可能就不会有多重字体跟变间距字体了。又因ؓWindows抄袭了麦金塔的用方式,如果当年我没q样做,大概世界上所有的个h计算机都不会有这些东西,C出现在我们看到的漂亮的字来了。当Ӟ当我q在大学里时Q不可能把这些点Ҏ滴预先串在一P但是q在十年后回,显得非常清楚。?br /><br /><span style="COLOR: red">      我再说一ơ,你不能预先把点点滴滴串在一P唯有未来回顾Ӟ你才会明白那些点Ҏ滴是如何串在一L。所以你得相信,你现在所体会的东西,来多少会连接在一块。你得信L个东西,直觉也好Q命q也好,生命也好Q或者业力。这U作法从来没让我失望Q也让我的h生整个不同v来。?/span><br /><br />      我的W二个故事,有关׃失去。?br /><br />      我好q-q轻时就发现自己爱做什么事。我二十岁时Q跟Steve Wozniak在我爸妈的R库里开始了Ҏ计算机的事业。我们拼命工作,Ҏ计算机在十年间从一间R库里的两个小伙子扩展成了一家员工超q四千h、市价二十亿金的公司,在那之前一q推Z我们最的作品Q麦金塔Q而我才刚q入人生的第三十个年_然后被炒鱉K。要怎么让自己创办的公司炒自己鱿|好吧Q当Ҏ计算机成长后Q我请了一个我以ؓ他在l营公司上很有才q的家伙来,他在头几q也实q得不错。可是我们对未来的愿景不同,最后只好分道扬镻I董事会站在他那边Q炒了我鱉KQ公开把我请了出去。曾l是我整个成q生z重心的东西不见了,令我不知所措。?br /><br />      有几个月Q我实在不知道要q什么好。我觉得我o企业界的前辈们失望-我把他们交给我的接力弄丢了。我见了创办HP的David Packard跟创办Intel的Bob NoyceQ跟他们说我很抱歉把事情搞砸得很厉害了。我成了公众的非常负面示范,我甚x要离开谷。但是渐渐的Q我发现Q我q是喜爱着我做q的事情Q在Ҏ的日子经历的事g没有丝毫改变我爱做的事。我被否定了Q可是我q是爱做那些事情Q所以我军_从头来过。?br /><br />      当时我没发现Q但是现在看来,被苹果计机开除,是我所l历q最好的事情。成功的沉重被从头来q的L所取代Q每件事情都不那么确定,让我自由q入q辈子最有创意的q代。?br /><br />      接下来五q_我开了一家叫做NeXT的公司,又开一家叫做Pixar的公司,也跟后来的老婆谈v了恋爱。Pixar接着制作了世界上W一部全计算机动ȝ影,玩具d员,现在是世界上最成功的动d作公司。然后,Ҏ计算Z下了NeXTQ我回到了苹果,我们在NeXT发展的技术成了苹果计机后来复兴的核心。我也有了个妙的家庭。?br /><br />      我很定Q如果当q苹果计机没开除我Q就不会发生q些事情。这帖药很苦口,可是我想Ҏ计算个病人需要这帖药?span style="COLOR: red">有时候,人生会用砖头打你的头。不要׃心。我信Q我爱我所做的事情Q这是q些q来让我l箋Cȝ唯一理由。你得找ZqQ工作上是如此,ҎZ是如此。你的工作将填满你的一大块人生Q唯一获得真正满的方法就是做你相信是伟大的工作,而唯一做伟大工作的Ҏ是爱你所做的事。如果你q没扑ֈq些事,l箋找,别停ѝ尽你全心全力,你知道你一定会扑ֈ。而且Q如同Q何伟大的关系Q事情只会随着旉愈来愈好。所以,在你扑ֈ之前Ql找Q别停顿。?/span><br /><br /><br />      我的W三个故事,关于M。?br /><br />      当我十七岁时Q我d一则格aQ好像是「把每一天都当成生命中的最后一天,你就会轻松自在。」这Ҏ影响pQ在q去33q里Q我每天早上都会照镜子,自问Q「如果今天是此生最后一日,我今天要q些什么?」每当我q箋太多天都得到一个「没事做」的{案Ӟ我就知道我必L所变革了。?br /><br />      提醒自己快死了,是我在h生中下重大决定时Q所用过最重要的工兗因为几乎每件事Q所有外界期望、所有名誉、所有对困窘或失败的恐惧Q在面对MӞ都消׃Q只有最重要的东西才会留下。提醒自己快MQ是我所知避免掉入自己有东西要失M的陷阱里最好的Ҏ。h生不带来Q死不带去,没什么道理不心而ؓ。?br /><br />      一q前Q我被诊断出癌症。我在早上七点半作断层扫描,在胰脏清楚出C个肿瘤,我连胰脏是什么都不知道。医生告诉我Q那几乎可以定是一U不M症,我大概活不到三到六个月了。医生徏议我回家Q好好跟亲h们聚一聚,q是ȝ对;l病人的标准。那代表你得试着在几个月内把你将来十q想跟小孩讲的话讲完。那代表你得把每件事情搞定,家h才会量L。那代表你得跟h说再见了。?br />   <br />      我整天想着那个诊断l果Q那天晚上做了一ơ切片,从喉咙入一个内视镜Q从胃进肠子Q插了根针进胰脏Q取了一些肿瘤细胞出来。我打了镇静剂,不醒ZQ但是我老婆在场。她后来跟我_当医生们用显微镜看过那些l胞后,他们都哭了,因ؓ那是非常见的一U胰脏癌Q可以用手术d。所以我接受了手术,康复了。?br /><br />      q是我最接近M的时候,我希望那会l是未来几十q内最接近的一ơ。经历此事后Q我可以比之前死亡只是抽象概忉|要更肯定告诉你们下面q些Q?br /><br />      没有人想歅R即佉K些想上天堂的人,也想zȝ上天堂。但是死亡是我们共有的目的地Q没有h逃得q。这是注定的Q因为死亡简直就是生命中最的发明Q是生命变化的媒介,送走老h们,l新生代留下I间。现在你们是新生代,但是不久的将来,你们也会逐渐变老,被送出人生的舞台。抱歉讲得这么戏剧化Q但是这是真的。?br /><br /><span style="COLOR: red">      你们的时间有限,所以不要浪Ҏ间活在别人的生活里。不要被信条所惑-盲从信条是zd别h思考结果里。不要让别h的意见没了你内在的心声。最重要的,拥有跟随内心与直觉的勇气Q你的内心与直觉多少已经知道你真正想要成Z么样的h。Q何其它事物都是次要的。?/span><br /><br />      在我q轻Ӟ有本奇的杂志叫做Whole Earth CatalogQ当q我们很q本杂志。那是一位住在离q不q的Menlo Park的Stewart Brand发行的,他把杂志办得很有诗意。那?960q代末期Q个机跟桌上出版还没发明,所有内定w是打字机、剪刀跟拍立得相机做出来的。杂志内Ҏ点像印在U怸的GoogleQ在Google出现之前35q就有了Q理惛_Q充满新奇工具与奇的注记。?br /><br />      Stewart跟他的出版团队出了好几期Whole Earth CatalogQ然后出了停刊号。当时是1970q代中期Q我正是你们现在q个q龄的时候。在停刊L底Q有张早晨乡间小路的照片Q那U你ȝ山时会经q的乡间\。在照片下有行小字: <br /><span style="COLOR: red">      求知若饥Q虚心若愚。?/span><br /><br />      那是他们亲笔写下的告别讯息,我L以此自许。当你们毕业Q展开新生z,我也以此期许你们。?br /><br />      求知若饥Q虚心若愚。?br /><br />      非常谢谢大家?<br /><br /><strong>原文Q?/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.shnenglu.com/nj-blog/aggbug/14704.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/nj-blog/" target="_blank">山日志</a> 2006-11-05 21:30 <a href="http://www.shnenglu.com/nj-blog/archive/2006/11/05/14704.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Scott Meyers最q一ơAhaQ时?/title><link>http://www.shnenglu.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.shnenglu.com/nj-blog/archive/2006/11/03/14595.html</guid><wfw:comment>http://www.shnenglu.com/nj-blog/comments/14595.html</wfw:comment><comments>http://www.shnenglu.com/nj-blog/archive/2006/11/03/14595.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/nj-blog/comments/commentRss/14595.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/nj-blog/services/trackbacks/14595.html</trackback:ping><description><![CDATA[    孟岩在自qblog?a title="提到? >提到?/a> Scott Meyers在Artima.com的C++ Source栏目中发表的一?×5的系列。其中最后一是Scott Meyers?a title="五个最重要的C++AhaQ时? >五个最重要的C++AhaQ时?/a> Q孟岩提C大家关注最后一个。如果关注过Scott Meyers和他的Effectivpd的话Q对他前四个AhaQ时d该都已经熟识了?br /><div>    q里仅翻译第五个Q?br /><h3>明白Boost?span style="FONT-STYLE: italic">shared_ptr</span>?span style="FONT-STYLE: italic">deleter</span>是如何工作的Q?004 </h3>Boost的引用计数智能指针shared_ptr有一个有的Ҏ,你可以传入一个函数或者一个函CQƈ且当?br />用计Cؓ零时Q它会对指向的对象调用这个deleter。让U的是,q看h很^凡,但是Lq段代码Q?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"><</span><span style="COLOR: #000000">typename  T</span><span style="COLOR: #000000">></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"><</span><span style="COLOR: #000000">typename U, typename D</span><span style="COLOR: #000000">></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.shnenglu.com/images/dot.gif" /><br />};<br /></span></div><br /></span></span></span></span></span>要注意的是在析构的期间shared_ptr<T>必须为类型ؓD的deleter做些安排Q以保它的调用Q然而shared_ptr<T>q不知道cdD到底是什么。此对象不能包含cd为D的数据成员,当然也不能有一个指向类型ؓD的对象的指针Q因为当对象成员数据声明的时候对于D好不知情。那么shared_ptr对象如何在构造期deleter被传入时保存它的t迹Qƈ且在E后的析构期使用它的呐?更一般的说法Q在一个对象的构造期间构造函数如何获得未知类型的信息Qƈ把类型的信息传给此对象,而对象不能保存关于此cdM提示?br /><br />{案很简单:此对象包含一个已知类型的基类指针QBoost它叫做 sp_counted_base Q,指向一个已l构造实例化的模板,此模板承自前面的基c,q用D作ؓ实例化参敎ͼBoost使用模板 sp_counted_impl_p ?sp_counted_impl_pd Q,使用一个在基类里声明,l承cM定义的虚函数来调?deleter QBoost使用 dispose Q。稍微简化了Q它看v来像下面q样Q?br />                            <img height="156" src="http://docs.google.com/File?id=dcjhdv5v_16f63d7b" width="343" align="absMiddle" /> <br />它是很明昄Q只要你看过它一ơ。但是只要你看过它一ơ,你就会体会到它可以被用到很多U类的地方,它打开了模板设计的新视野,模板化类使用相对较少的模板参敎ͼshared_ptr 只是其中一个)可以引用不受数量限制的当前不知名cd的信息。当我意识到我接q的东西Q我不能止地露赏的W容q摇晃我的脑袋?br /><br /></div><img src ="http://www.shnenglu.com/nj-blog/aggbug/14595.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/nj-blog/" target="_blank">山日志</a> 2006-11-03 01:10 <a href="http://www.shnenglu.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 Developerhttp://www.shnenglu.com/nj-blog/archive/2006/11/02/14559.html山日志山日志Wed, 01 Nov 2006 16:00:00 GMThttp://www.shnenglu.com/nj-blog/archive/2006/11/02/14559.htmlhttp://www.shnenglu.com/nj-blog/comments/14559.htmlhttp://www.shnenglu.com/nj-blog/archive/2006/11/02/14559.html#Feedback3http://www.shnenglu.com/nj-blog/comments/commentRss/14559.htmlhttp://www.shnenglu.com/nj-blog/services/trackbacks/14559.htmlcodeproject.comQ原文链接与工具及其源代码下载点?a class="" title="" target="_blank">q里?br />Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q?br /> 导引QWINDOWSX.H头文件简化Win32 SDK~程

许多的新手或者调试程序员在编写C/C++的Windows APIE序旉要面对像意大利面一Lswitch...case代码块。当你需要加入一个消息处理到你的H口处理q程中时Q在些代码块中查找例如:WM_COMMAND?span style="COLOR: rgb(255,0,0)">WM_CHARQ是相当让h恐惧的事情?br />
早在Windows 3.1时代的Windows软g开发工具包和C/C++7.0~译器就附带一个包含一千多行Windows处理代码的头文g。这个头文g?span style="FONT-STYLE: italic"><windowsX.h>
Q它包含
了许多有用的宏。微软的对这个头文g的介l如下:

  • 对CE序做更严格的类型检查的STRICT宏?
  • 一些简化Windows~程的通用操作的宏?
  • 一些简化与Windows控g交流的控件宏?
  • 消息分流器(一U方便,Mq且cd安全的处理消息的ҎQ以及它们在Windows环境下的参数和返回倹{?

在Message Cracker Wizard被设计出C前,我就从用这些的宏中获得了效率。如果你?span style="FONT-STYLE: italic">Windows.h的简单描q感兴趣Q你可以参见MS知识库的文章#8356 ?br />
好了Q让我们来介l消息分器的便利,以及Qؓ什么这里发布的工具可以你编写代码的效率?br />
当你在编写Win32 SDKE序Ӟ你处理窗口消息通过一个窗口函敎ͼ通常命名?span style="COLOR: rgb(255,0,0)">WndProc。在Windows C E序中常见的是窗口函数通过关键?span style="COLOR: rgb(51,51,255)">switch和分支标{?span style="COLOR: rgb(51,51,255)">case处理所有你需要处理的消息?br />
可以料想的是我们通常需要在ȝ口中处理WM_COMMANDQ?/span>WM_KEYUPQ?/span>WM_CLOSE?/span>WM_DESTROY消息。理Z我们会把H口函数写成q样Q?br />
LRESULT CALLBACK MainWndProc (HWND hwnd, UINT msg,   WPARAM wParam, LPARAM lParam)
{
  
switch
(msg)
  {
    
case
 WM_COMMAND:
    
// 

    break;    
     
    
case
 WM_KEYUP:
    
// 

    break;

    
case
 WM_CLOSE:
    
// 

    break;       
     
    
case
 WM_DESTROY:
    
//

    break;      
        
    
default
:   
       
return
 DefWindowProc(hwnd, msg, wParam, lParam);
  }
}
q是自Windows 1.0时代以来处理Windows消息使用最多的Q确实地Q它工作。但是问题是当你开始向你程序中加入更多复杂的特性,例如 MDIQOLEQ通用控gQ等{,你会获得一个行C千记的窗口函数。你开始反复用PageDn和PageUp键蟩跃,来寻找你需要修改的消息?br />
q是使用消息分流器的W一个好处:它们提供了处理函数来?span style="COLOR: rgb(51,51,255)">case标签意大利面Q就像MFC做的那样?br />
W二个好处是正确的参数规范化了你的处理函数的使用。你可以单地使用switch(id)来替?/span>switch(LOWORD(wparam))Q因Z?span style="COLOR: rgb(204,0,0)">id作ؓ一个“分器”的参数传递给消息函数Ӟ{同?span style="COLOR: rgb(204,0,0)">LOWORD(wparam)?br />
消息处理?span style="COLOR: rgb(204,0,0)">HANDLE_MSG定义?span style="FONT-STYLE: italic">windows.h中,如下Q?/span>

#define HANDLE_MSG(hwnd, message, fn) \
    
case (message) : return HANDLE_##message((hwnd), (wParam), (lParam), (fn)) 

如你从上面宏定义中可以想到的是,你的代码{换成“消息分器”版本,你必L持分宏Q?span style="COLOR: rgb(204,0,0)">HANDLE_MSGQƈ且用函数来处理消息。现在将HANDLE_MSG宏加入到H口函数中来。这个宏需要三个参敎ͼ一个窗口句?hwnd)Q你要处理的消息(WM_xxxx)Q以及你用来处理此消息的函数。ؓ了更好的说明Q我把之前的H口函数替换成下面的消息分流版:
LRESULT CALLBACK MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  
switch(msg)
  {
    HANDLE_MSG (hwnd, WM_COMMAND, OnCommand);
    HANDLE_MSG (hwnd, WM_KEYUP,   OnKeyup);
    HANDLE_MSG (hwnd, WM_CLOSE,   OnClose);
    HANDLE_MSG (hwnd, WM_DESTROY, OnDestroy);
    
default:
        
return DefWindowProc(hwnd, msg, wParam, lParam);
  }
}


哇!q是更好的,z的q且Ҏ控制的窗口函数。现在你需要定义的的消息处理函?OnKeyUp, OnClose?span style="COLOR: rgb(204,0,0)">OnDestroy)。更加便利的是你可以使用Visual Studio IDE跛_你消息处理函敎ͼ


问题是每一ơ你增加一个消息处理你都必L?span style="FONT-STYLE: italic">WINDOWS.H里的定义Q以匚w你的消息处理函数的参数类型,因ؓ你不能随意的使用参数cdQ处理函数的格式是清楚定义的。在头文件中反复的查找是单调乏味的Q务,且容易出错。消息分器Wizard工具来搭救你了:它允怽_脓M你需要的消息处理的正的参数。如果你刚刚开始编写代码,它还可以生成一个窗口模板或者对话框函数作ؓ你处理窗口消息的开始?br />
Message forwarding宏:另一个WINDOWS.H特色

头文?span style="FONT-STYLE: italic">windowsx.h的另一个特色大U是message forwarding。它用来“拆除”消息处理函数的参数为有效的WPARAM?span style="COLOR: rgb(204,0,0)">LPARAM的?/span>Q以调用诸如PostMessageQ?span style="COLOR: rgb(204,0,0)">SendMessageQ?span style="COLOR: rgb(204,0,0)">CallWindowProc{等Q此cȝ函数?br />

假设你你希望使用SendMessage函数来发?span style="COLOR: rgb(204,0,0)">WM_COMMAND消息l父H口Q通过以一个通知?span style="COLOR: rgb(204,0,0)">BN_DBLCLK来“模拟”双M个命名ؓIDC_USERCTL的控件。你通常会这样写Q?br />
SendMessage (hwndParent, WM_COMMAND,
    MAKEWPARAM(IDC_USERCTL, BN_DBLCLK),
     (LPARAM)GetDlgItem(hwnd, ID_USERCTL));

q是一个复杂的的语法:函数SendMessage期望WPARAM参数的底字节是控件的IDQ高字节是通知码;q且我们要通过API函数GetDlgItem获得控g句柄Q传l?/span>LPARAM参数?br />
上面的代码可以用Windows.h的message forwarding宏替换,FORWARD_WM_XXXX。对于每一个消息,forwarding宏都使用和消息分器生成的消息处理函数相同的“捆扎”参敎ͼ增加你希望调用的函数q且传给它“拆除”后?span style="COLOR: rgb(204,0,0)">LPARAM/WPARAMs。例如,消息分流器Wizard?span style="COLOR: rgb(204,0,0)">WM_COMMAND消息和窗口IDmyWnd生成如下的函数原型:
void myWnd_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
好了Q这些分器参数也同栯用于forwarding?-因此Q如你所期望的,我们之前调用SendMessage函数时展现的混ؕ可以减少了:
FORWARD_WM_COMMAND (hwndParent, IDC_USERCTL, 
GetDlgItem(hwnd, ID_USERCTL), BN_DBLCLK, SendMessage);
q种方式非常便,q且可以为所有消息分器Wizard支持的消息工作?br />

使用消息分流Wizard工具

当你q行消息分流器WizardӞ你可以看C面的H口Q?br />


Wizard在左上角的列表框里ؓ你提供了WINDOWS.H里有的消息处理,你可以点M个或者多个消息。你可以在窗口ID~辑框里指定一个窗口标识,以指定你要发送消息的
H口。通用的ID?
MainWnd QAbout (关于对话框)Q等{。这个标识会体现在消息处理函CQ和 HANDLE_MSG 宏中Q如果你刚刚开始编写代码,它还可以体现在窗
?对话框处理函C。?Make Window Procedure”选定框的作用是:允许你通过选定的消息分器的宏来生成一个窗?对话框函数的框架。以q种方式来开始一
个Windows API目Q你可以清晰的编写和l织你的代码Q当然还有,避免错误。在H口下面的两个编辑框会包含分器的宏和处理所选消息的函数Q只是原型)生成的代
码。要注意的是Q当你选择?span style="FONT-WEIGHT: bold">Make Window Procedure
”时H口处理函数的模板代码不出现在这里:它仅体现在你点击了?span style="FONT-WEIGHT: bold">Copy Macro
”时复制C的C++~辑器中
的代码里?br />
让我们通过例子来快速的览消息分流器Wizard工具的特性。记住你必须先通过#include <windowsx.h>头文g<windowsx.h>包含C.C/.CPP文g中?br />
快速浏览消息分器WizardҎ?br />
让我们开始吧。假设你已经~写了你?/font> WinMain 的基本代码:已经成功填充?WNDCLASS l构Q注册了H口c,q且~写了消息@环。现在你需要一个ؓ你主函数~写
的消息处理函数?br />
打开消息分流器Wizard。我们需要ؓ我们的窗口选择消息Q因为MCW需要用它来生成我们的消息处理函数。如你所知,WindowsE序非常常见的处理消息是
WM_CLOSE ?br />WM_DESTROY ?WM_CREATE Q所以让我们选择消息分流器处理这些消息来创徏H口函数。然后,我们创徏H口函数的主体消息处理函数?br />
在列表框中选择
WM_CLOSE , WM_DESTROY ?WM_CREATE 。因为此H口是我们程序的ȝ口,我们选用main做ؓH口的ID。这个窗口ID表识了我们的H口/对话框,q且
使分宏和出理函C为后~。当Ӟ你要使特定窗口的所有消息处理保持一致。观察下面的~辑框。它们显C?span style="COLOR: rgb(204,0,0)"> HANDLE_MSG 分流宏和兌的消息处理函数的原型?/span>



但是Q等一?.....我们说我们需要一个准备好的窗口处理函数。所以单几Z?span style="FONT-WEIGHT: bold">Make Window Procedure”选定框,q且认Window 单选按钮已l被选择了。现?br />我们准备好了。要注意的是Q对话框的工作也像这P但是要改变处理函Cؓ对话框类型?br />
首先Q我们需要我们源代码的窗口处理函数。点几Z?span style="FONT-WEIGHT: bold">Copy Macro”按钮(或者?span style="FONT-STYLE: italic">Ctrl-MQ,最化WizardQ或者把它放C边)Q回C的IDEq且从剪贴板_脓
Q?span style="FONT-STYLE: italic">Ctrl-VQ代码到你的H口函数的位|?/font>Voil֙Q阿根h拉丁语,认识的通知下)Q你可以得到像下面的代码Q?
//
// main  Window Procedure
//
LRESULT CALLBACK main_WndProc (HWND hwnd, UINT msg, WPARAM wParam,   LPARAM lParam)
{
  
switch
(msg)
  {
    HANDLE_MSG (hwnd, WM_CLOSE, main_OnClose);
    HANDLE_MSG (hwnd, WM_CREATE, main_OnCreate);
    HANDLE_MSG (hwnd, WM_DESTROY, main_OnDestroy);
      
//// TODO: Add window message crackers here

  defaultreturn DefWindowProc (hwnd, msg, wParam, lParam);
  }
}


q个H口处理函数以三个消息分宏展开工作Qƈ且,通过TODO注释提示你记得必dq里d消息分流器宏。当你只是要d一?/font> HANDLE_MSG 宏到H口函数中时Q?br />记得取消?span style="FONT-WEIGHT: bold">Mke Window Procedure”选定框的选择?/font>

但是q些代码现在q什么都做不了,因ؓ我们q需要添加三个我们需要的消息处理函数。回到消息分器Wizard工具的界面,q且单击?span style="FONT-WEIGHT: bold">Copy Function”按钮。切
换到你的代码Q用鼠标定位C需要函C体插入的位置Q然后用Ctrl+V或者菜单Edit/Paste_脓。Wizard自动生成函数Q?main 标识H口IDQƈ修正参数cd
使之W合 WINDOWSX.H 头文件的?

//
//Process WM_CLOSE message for window/dialog: main
//
void
 main_OnClose(HWND hwnd)
{
  
// TODO: Add your message processing code here

}
//

//  Process WM_CREATE message for window/dialog: main
//
BOOL main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
  
// TODO: Add your message processing code here

}
//

//  Process WM_DESTROY message for window/dialog: main
//
void
 main_OnDestroy(HWND hwnd)
{
  
// TODO: Add your message processing code here

}




Wizardq可以自动生成开头注释,和TODO行以提醒你添加代码。现在你可以d消息处理了,可以是简单的处理处理逻辑Q或者复杂窗口函数。你也可以通过选定框移?br />注释?br />
更多的消息分器WizardҎ?br />
消息qo

你可以过滤你暂时不打处理的消息。单几Z?span style="FONT-WEIGHT: bold">Filters..
”按钮(或者Ctrl+LQ,你会打开下面对话框。列表的消息按类型分c(分类标准来自Microsoft Spy++的效果)Q?br />你可以取消选定你不处理的消息?br />


要注意的是在 v2.0 当前的问题是Q当你打开消息qo对话框时所有类型的消息都是选定的,当你点击OKQ之前选定的消息会丢失Q这q不意味着你粘贴到目标代码?br />内容会消失)?br />


z窗口模?/span>

你可能需要减消息分WizardH体的大。这可以通过取消菜单 View ??span style="FONT-WEIGHT: bold">Show Target Code
”选项的选定Q或者用Ctrl+F11Q。主H口会取消目标代码区域:

H体透明Q取消注释和|顶

Q译注:SorryQ暂不做译了,你可以通过试菜单 View 的其它几个选项自己体会^_^Q?br />


未来Ҏ?br />
下面的特性会在下一ơ发布时实现Q?/span>
  • 帮助文g?
  • 所有消息分的参数和消息的完整帮助?
  • 支持WTLQ?)
  • H口ID和配|保存(q个会在下一?.x版本实现Q?
  • 目配置和“消息映”(a la MFCQ(译注Q好像是西班牙语Q不认识:PQ(q个也会在之后的2.5版本实现Q?br />

快乐的编E!

我希望这个小工具可以让每?Windows SDK E序员感兴趣Qƈ且干净的编?Win32 API E序。我乐于接受改进q个工具的主意。如果你发现q个E序很好用,L我发邮gQ因为我非常高兴听到M好的意见?br />
谢谢所有支持!QYou know who you areQ(译注Q不太明白这个要表达什么意思,“你知道你是谁!”乎Q)

M时候,打开我的主页Q你可以在那里找到这个程序的最新更新?br />
历史Q?br />  ?..

关于作者:
Hern֙n Di Pietro

业余E序员?br />
开始于1986q_在Commodore 64上编写BASICE序?br />?990q第一?8086 PC 上开始编?QB 4.x?br />1995-1996q{UdVisual Basic?br />2002q_23岁时开始编写C++E序Qƈ?Windows API 上瘾?br />
主页Q?http://usuarios.lycos.es/hernando





山日志 2006-11-02 00:00 发表评论
]]>
ACM初体?/title><link>http://www.shnenglu.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.shnenglu.com/nj-blog/archive/2006/09/20/12771.html</guid><wfw:comment>http://www.shnenglu.com/nj-blog/comments/12771.html</wfw:comment><comments>http://www.shnenglu.com/nj-blog/archive/2006/09/20/12771.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/nj-blog/comments/commentRss/12771.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/nj-blog/services/trackbacks/12771.html</trackback:ping><description><![CDATA[    q是我第一此参加ACM竞赛Q我想也是最后一ơ了。呵呵,要毕业啦^_^<br />    8?8日接到nƣ苹的电话,说是有一个编E比赛要l队参加Q邀h加入她的队伍里?a target="" class="" title="" href="/nj-blog/gallery/image/1211.html"><img alt="" src="http://www.shnenglu.com/images/cppblog_com/nj-blog/2644/t_acm5.JPG" align="" border="" height="90" hspace="0" vspace="0" width="120" /></a><br />    因ؓ不考研Q开学比较闲Q其实我一向是个闲人啦^_^Q,所以不假思烦q应了?br />三天后去pML老师那里报名Q这才第一ơ见到听d久的另一个队友:Uv?a target="" class="" title="" href="/nj-blog/gallery/image/1212.html"><img alt="" src="http://www.shnenglu.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?0号预赛,勉强通过?6号在哈工E的体育馆里册Q做Z5道题。大概组委会念在是黑龙江省的W一ơ区域性竞赛,AC?道题的全l了三等奖,一共有32个。呵呵,特h甩卖了。最多的也只AC?道题Q这些是一{奖Q?支队伍?道题的是二等奖,6支队伍?br /><a target="" class="" title="" href="/nj-blog/gallery/image/1207.html"><img alt="" src="http://www.shnenglu.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.shnenglu.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.shnenglu.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.shnenglu.com/images/cppblog_com/nj-blog/2644/t_acm4.JPG" align="" border="" height="90" hspace="0" vspace="0" width="120" /></a><br />    从接到欣苹的通知那天到决赛,我只准备?9天,感觉很仓促。如果上天能l我再来一ơ的Z的话......<br />    不说废话了,q是十分高兴可以有这样一ơ机会和q么多高水^的h同场竞技Q让我认识到自己在程序之路上原来q只是个井底之蛙。要学习的东西还是很多,努力Q加油!<br />    而且意外收获了一个三{奖Q哈哈^_^<br /><img src="http://www.shnenglu.com/images/cppblog_com/nj-blog/2644/r_acm2.JPG" /><br /><br /><img src ="http://www.shnenglu.com/nj-blog/aggbug/12771.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/nj-blog/" target="_blank">山日志</a> 2006-09-20 23:18 <a href="http://www.shnenglu.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)http://www.shnenglu.com/nj-blog/archive/2006/08/16/11264.html山日志山日志Tue, 15 Aug 2006 16:24:00 GMThttp://www.shnenglu.com/nj-blog/archive/2006/08/16/11264.htmlhttp://www.shnenglu.com/nj-blog/comments/11264.htmlhttp://www.shnenglu.com/nj-blog/archive/2006/08/16/11264.html#Feedback0http://www.shnenglu.com/nj-blog/comments/commentRss/11264.htmlhttp://www.shnenglu.com/nj-blog/services/trackbacks/11264.html 2. 函数模板 checked_delete() ?/span> checked_array_delete()

<boost/checked_delete.hpp> 定义了两个函数模?/span> checked_delete ?/span> checked_array_delete Q?/span> q有两个cL?/span> checked_deleter ?/span> checked_array_deleter?/span>

当我们利用指针删除一个对象的时候,对象cd是否完整军_了对象是否能够被正确删除。但是,如果你用 delete d除一个类型ƈ不完整的对象的指针,~译器ƈ不会l你提供M错误信息Q好吧,有些~译器会l出警告信息Q但是程序员通常会忽略警告信息)Q但是这样做的结果却是对象的析构函数Ҏ没有被调用?/span>

所以,我们应当使用更严厉的手段止q种事情的发生。比如说使用 checked_delete 代替 delete 来删除指针。当指针所指向的是一个不完全cdӞ checked_delete 会ɾ~译器发出错误信息?/span>

class  testQ?/span> // 有声明,但是忘记了定义,或是忘记    
          
// 包含定义文gQtest是一个不完全cd

main()
{
test 
*  pt  =  NULL;
delete pt;  
//
 有时会有警告信息Q?br />             // 但有时什么都没有?/span>
checked_delete(pt);  //  发出错误信息?/span>
}

checked_array_delete 是用来对应于 delete [ ] operator Q?/span> checked_deleter ?/span> checked_array_deleter 是可以配接的仿函数版本?/span>

3. 函数模板 next() ?/span> prior()
包括

template < class T > T next(T x);
template
< class T, class  Distance >
T next(T x, Distance n);
template
< class T >
T prior(T x);
template
< class T, class  Distance >
T prior(T x, Distance n);

函数模板对传入的指针Q智能指针或是P代器做递增或递减Qƈ传回它。用法如下:

const  std::list < T > ::iterator p  =  get_some_iterator();
const  std::list < T > ::iterator prev  =
 boost::prior(p);
const  std::list < T > ::iterator next  =  boost::next(prev,  2 );

事实上, T next(T x) ?/span> T prior(T x) 分别调?/span> operator++ ?/span> operator-- Q?/span> T next(T x, Distance n) ?/span> T prior(T x, Distance n) 则调?/span> std::distance(T x, size_t n) ?

4.noncopyable c?/span>

如果你需要设计一个不可以被复制的c,那么你就要明地它的拷贝构造函数和 operator = () 攑ֈ private 声明下面?/span> Boos\utility 准备了一个基c?/span> noncopyable Q你只需要让你的cȝ承自 noncopyable 可以获得这个性质。对你的cL说这也是一个显式的声明Q“我是不可以被复制的Q?/span>
用法Q?/span>

#include  < boost / utility.hpp >

class
 ResourceLadenFileSystem : boost::noncopyable {


5 Q函数模?/span> addressof()

函数模板q回一个对象的真实地址Q当然这是交l指针了Q:

template < typename T > inline T *                 addressof(T &  v);
template
< typename T > inline const  T *          addressof( const  T &
 v);
template
< typename T > inline volatile  T *       addressof( volatile  T &
 v);
template
< typename T > inline const volatile T *  addressof( const volatile T & v);

我知道你惌Qؓ什么不是简单的调用operator&()。因?/span>c++允许重蝲operator&()Q所以有时用它获得的ƈ不是对象的真实地址Q而是~写重蝲operator&()代码的作者希望给你的那个。如果你却是希望获得的是q个对象的地址Q?/span>addressof():

#include <boost/utility.hpp>
struct useless_type {};

class
 nonaddressable {
  useless_type 
operator&() const
;
};

void
 f() {
  nonaddressable x;
  nonaddressable
* xp =
 boost::addressof(x);
  
// nonaddressable* xpe = &x; //
error! operator&()已经被重载,
                              
//它返回的是useless_type的指?/span>
}




上述的所有东襉K可以单的通过在你的源文g开头处写上Q?br />
#include <boost\utility.hpp>
using namespace boost;
可以用了。当然我是指你机器上已经有boostq个奇妙的库Qƈ且正配|^_^

山日志 2006-08-16 00:24 发表评论
]]>
Boost/utility里有什么东西?(1)http://www.shnenglu.com/nj-blog/archive/2006/08/11/11144.html山日志山日志Fri, 11 Aug 2006 15:59:00 GMThttp://www.shnenglu.com/nj-blog/archive/2006/08/11/11144.htmlhttp://www.shnenglu.com/nj-blog/comments/11144.htmlhttp://www.shnenglu.com/nj-blog/archive/2006/08/11/11144.html#Feedback0http://www.shnenglu.com/nj-blog/comments/commentRss/11144.htmlhttp://www.shnenglu.com/nj-blog/services/trackbacks/11144.html ?/span> STL ?/span> utility 一P boost/utility 里包含了一些实用的工兗?/span>

首先?/span>   Base-from-Member Q?/span>

有时你可能需要依赖成员变量来初始化基c,像这P

class  fdoutbuf
    : 
public  std::streambuf
{
public :
    
explicit  fdoutbuf(  int  fd );
    
//
};

class  fdostream
    : 
public  std::ostream
{
protected :
    fdoutbuf buf;
public :
    
explicit  fdostream(  int  fd )
        : buf( fd ), std::ostream( 
& buf )
        {}
    
//
};


但是Q这?/span> fdostream 的构造函数的初始化是错误的,因ؓ c++ 语法要求基类的初始化要先于成员变量的初始化?/span> Base-from-Member 提供的解决之道如下:

class  fdoutbuf
    : 
public  std::streambuf
{
public :
    
explicit  fdoutbuf(  int  fd );
    
//
};

class  fdostream
    : 
private  boost::base_from_member < fdoutbuf >
    , 
public  std::ostream
{
    
//  Helper typedef's
    typedef boost::base_from_member
< fdoutbuf >   pbase_type;
    typedef std::ostream                        base_type;
public :
    
explicit  fdostream(  int  fd )
        : pbase_type( fd ), base_type( 
& member )
        {}
    
//
};

模板c?/span> template < typename MemberType, int UniqueID = 0 >
        class boost::base_from_member;
是一个外覆类Q姑且这么叫?/span> ^_^ Q?br />如上Q私有?/span> base_from_member Q原先的成员变量做?/span> base_from_member 的成员变?/span> member 先于基类 base_type 初始化,q样所需的依赖关pd以满뀂事实上比这更好的是Q?/span> base_from_member 的构造函数是模板函数Q它可以?/span> 0 ?/span> 10 个参敎ͼ参数cd可以各不相同?/span>

山日志 2006-08-11 23:59 发表评论
]]>
ƷþþþþþĻ| þþƷƷëƬ| ޹Ʒþþϼ2| ھƷ99þ| ƷþþþӰ| ŷ޾ƷþþavӰ| 99þþƷѿһ | ھƷþۺ88| Ʒþþþþþö| þþƷһ| þþùƷ| þþƷҹɫA| ͵͵þþþվ| þˬˬƬav鷳 | پþþƷþ| þùƷһ| 777þþƷһ| þùҹƷһ| 鶹þ| ƷһþaaaƬ| þþþavרˮ| þ߿߿| þ̳| ٸþĻһ| 77777ҹþö| Ʒþþþþһ| þۺϾɫۺŷȥ| þþþ99ƷƬֱ| 99þó˹Ʒ| þ97þ97Ʒӿϼ| Ĺ˾Ʒþò | ˾þ뾫ƷĻ| þ޾Ʒۿ| Ըߺþþþþþþ| Ʒ˿þþþþò| ޾Ʒþþþþ| þþƷҹƬ| ҹƷþþþ9999| þùӾƷŮ| þ99žŹѿС˵| þˬˬƬav|