<?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++博客-c++探索</title><link>http://www.cppblog.com/bloodsuck/</link><description>玩玩</description><language>zh-cn</language><lastBuildDate>Thu, 20 Nov 2008 18:48:12 GMT</lastBuildDate><pubDate>Thu, 20 Nov 2008 18:48:12 GMT</pubDate><ttl>60</ttl><item><title>数组浅析</title><link>http://www.cppblog.com/bloodsuck/archive/2008/06/06/52331.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Fri, 06 Jun 2008 02:37:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2008/06/06/52331.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/52331.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2008/06/06/52331.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/52331.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/52331.html</trackback:ping><description><![CDATA[int a[10]<br>int b[20][10]<br><br>&nbsp;类型：<br>a:&nbsp;&nbsp; int [10]<br>b:&nbsp;&nbsp;&nbsp;int [20][10]<br>a, b 都是右值<br>&nbsp;精确装换级别类型：<br>&nbsp;a---&gt;int *<br>b ----&gt;int (*)[10]<br>&nbsp; 地址类型<br>&amp;a : int (*)[10]<br>&amp;b:int (*)[20][10]&nbsp;<br>&nbsp;&nbsp; <br><br>问题：如何在堆中动态分配多维数组<br>思路：降维分配<br>int ** p;<br>int a=30;<br>int b=50;<br>p=new int * [30];//2维分配<br>*(p+1)=new int [50];<br>*(p+2)=new int [50];<br>一维是连续地址<br>2维是非连续的<br><br>另种思路：结构指针<br>struct color<br>{<br>&nbsp; int * a;<br>}<br>color * b;<br>b=new color[50];<br>b[1].a=new int [60];
<img src ="http://www.cppblog.com/bloodsuck/aggbug/52331.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2008-06-06 10:37 <a href="http://www.cppblog.com/bloodsuck/archive/2008/06/06/52331.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>1秒钟的命运</title><link>http://www.cppblog.com/bloodsuck/archive/2007/07/18/28261.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Wed, 18 Jul 2007 02:42:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2007/07/18/28261.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/28261.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2007/07/18/28261.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/28261.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/28261.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在这种关键的时刻，那些平时慢慢悠悠顺序发生和并列发生的事，都压缩在这样一个决定一切的短暂时刻表现出来。这一时刻对世世代代作出不可改变的决定，它决定着一个人的生死、一个民族的存亡甚至整个人类的命运。 <br>命运总是迎着强有力的人物和不可一世者走去。多少年来，命运总是使自己屈从于这样的个人：凯撒、亚历山大、拿破仑，因为命运喜欢这些像自己那样不可捉摸的强权人物。</p>
<p>但是有时候，当然，这在任何时代都是极为罕见的，命运也会出于一种奇怪的心情，把自己抛到一个平庸之辈的手中。有时候——这是世界历史上最令人惊奇的时刻——命运之线在瞬息时间内是掌握在一个窝囊废手中。英雄们的世界游戏像一阵风暴似的也把那些平庸之辈卷了进来。但是当重任突然降临到他们身上时，与其说他们感到庆幸，毋宁说他们更感到骇怕。他们几乎都是把抛过来的命运又哆哆嗦嗦地从自己手里失落。一个平庸之辈能抓住机缘使自己平步青云，这是很难得的。因为伟大的事业降临到渺小人物的身上，仅仅是短暂的瞬间。谁错过了这一瞬间，它绝不会再恩赐第二遍。</p>
<p>格鲁希</p>
<p>维也纳会议正在举行。在玩弄权术和互相争吵之中，像一枚嗖嗖的炮弹飞来这样的消息：拿破仑这头被困的雄狮自己从厄尔巴岛的牢笼中闯出来了；拿破仑赶走了国王；军队又都狂热地举着旗帜投奔到他那一边&#8230;&#8230;好像被一只利爪攫住，那些刚刚还在互相抱怨的大臣们又都聚集在一起，他们再次联合起来，彻底击败这个篡权者。威灵顿开始从北边向法国进军，一支由布吕歇尔布统率的普鲁士军，作为他的增援部队从另一方向前进。施瓦尔岑贝格在莱茵河畔整装待发；而作为后备军的俄国军团，正带着全部辎重，缓慢地穿过德国。</p>
<p>拿破仑看清了这种致命的危险。他必须在普鲁士人、英国人、奥地利人联合成为一支欧洲盟军前就将他们分而攻之，各个击破。于是他匆忙把赌注押在欧洲流血最多的战场——比利时。（1815年）6月16日拿破仑大军的先头部队在林尼与普鲁士军遭遇，并将普军击败。这是这头雄狮的第一次猛击，这一击非常厉害，然而却不致命。被击败而并未被消灭的普军向布鲁塞尔撤退。</p>
<p>拿破仑准备向威灵顿的部队进攻。他不允许自己喘息，也不允许对方喘息，因为每拖延一天，就意味着给对方增添力量。17日，拿破仑率领全军到达四臂村高地前，威灵顿这个对手已在高地上筑好工事，严阵以待。拿破仑充分估计到自己面临的各种危险，即布吕歇尔的军队仅仅是被击败，而并未被消灭。这支军队随时可能与威灵顿的军队会合。为了防止这种可能性，他抽调出一部分部队去跟踪追击普鲁士军，以阻止他们与英军会合。</p>
<p>他把这支追击部队交给了格鲁希元帅指挥。格鲁希，一个气度中庸的男子，老实可靠，兢兢业业。他既没有缪拉那样的胆识魄力，也没有圣西尔那样的足智多谋，更缺乏内伊那样的英雄气概。关于他，没有神话般的传说，也没有谁把他描绘成威风凛凛的勇士。他从戎20年，他是缓慢地、一级一级地升到元帅的军衔。拿破仑大概也知道，格鲁希既不是气吞山河的英雄，也不是运筹帷幄的谋士。但是他自己的元帅，一半已在黄泉之下，而其余几位已对这种没完没了的风餐露宿的戎马生活十分厌倦，正怏怏不乐地呆在自己的庄园里呢。所以，拿破仑是出于无奈才对这个中庸的男子委以重任的。</p>
<p>17日上午11时，拿破仑第一次把独立指挥权交给格鲁希元帅。就在这一天，在这短暂的瞬间，唯唯诺诺的格鲁希跳出一味服从的军人习气，自己走进世界历史的行列。拿破仑的命令是清楚的：当他自己向英军进攻时，格鲁希务必率领交给他的三分之一兵力去追击普鲁士军，而且他必须始终和主力部队保持联系。</p>
<p>格鲁希元帅踌躇地接受了这项命令。他不习惯独立行事。只是当他看到皇帝的天才目光，才感到心里踏实，应承下来。格鲁希的部队在瓢泼大雨中出发。</p>
<p>决定世界历史的一瞬间</p>
<p>18日上午11点，炮手们接到命令：用榴弹炮轰击山头上的身穿红衣的英国士兵。接着，内伊——这位&#8220;雄中之杰&#8221;，率领步兵发起冲锋。从上午11点至下午1点，法军师团向高地进攻，一度占领了村庄和阵地，但又被击退下来，继而又发起进攻。在空旷、泥泞的山坡上已覆盖着1万具尸体。可是除了大量消耗以外，什么也没有达到。双方的军队都已疲惫不堪，双方的统帅都焦虑不安。双方都知道，谁先得到增援，谁就是胜利者。威灵顿等待着布吕歇尔；拿破仑盼望着格鲁希。</p>
<p>但是，格鲁希并未意识到拿破仑的命运掌握在他自己手中，他只是遵照命令于17日晚间出发，按预计方向去追击普鲁士军。因为敌人始终没有出现，被击溃的普军撤退的踪迹也始终没有找到。</p>
<p>正当格鲁希元帅在一户农民家里急急忙忙进早餐时，他脚底下的地面突然微微震动起来。所有的人都悉心细听。从远处一再传来沉闷的、渐渐消失的声音：这是大炮的声音，是远处炮兵正在开炮的声音，不过并不太远，至多只有三小时的路程。这是圣让山上的炮火声，是滑铁卢战役开始的声音。副司令热拉尔急切地要求：&#8220;立即向开炮的方向前进！&#8221;所有的人都毫不怀疑：皇帝已经向英军发起攻击了，一次重大的战役已经开始。可是格鲁希却拿不定主意。他习惯于唯命是从，他胆小怕事地死抱着写在纸上的条文——皇帝的命令：追击撤退的普军。热拉尔看到他如此犹豫不决，便恳切地请求：至少能让他率领自己的一师部队和若干骑兵到那战场上去。格鲁希考虑了一下。他只考虑了一秒钟。</p>
<p>然而格鲁希考虑的这一秒钟却决定了他自己的命运、拿破仑的命运和世界的命运。格鲁希使劲地摇了摇手说，把这样一支小部队再分散兵力是不负责任的，他的任务是追击普军，而不是其他。就这样，他拒绝了这一违背皇帝命令的行动。而决定性的一秒钟就在这一片静默之中消逝了，它一去不复返，以后，无论用怎样的言词和行动都无法弥补这一秒钟——威灵顿胜利了。</p>
<p>格鲁希的部队继续往前走。随着一小时一小时的过去，格鲁希越来越没有把握，因为令人奇怪的是，普军始终没有出现。显然，他们离开了退往布鲁塞尔去的方向。接着，情报人员报告了种种可疑的迹象，说明普军在撤退过程中已分几路转移到了正在激战的战场。如果这时候格鲁希赶紧率领队伍去增援皇帝，还是来得及的。但他只是怀着愈来愈不安的心情，继续等待着消息，等待着皇帝要他返回的命令。可是没有消息来。只有低沉的隆隆炮声震颤着大地，炮声却愈来愈远。孤注一掷的滑铁卢搏斗正在进行，炮弹便是投下来的铁骰子。</p>
<p>滑铁卢的下午</p>
<p>时间已经到了下午一点钟。拿破仑的四次进攻虽然被击退下来，但威灵顿主阵地的防线显然也出现了空隙。拿破仑正准备发起一次决定性的攻击。这时，他发现东北方向有一股黑的人群迎面奔来。一支新的部队！</p>
<p>所有的望远镜都立刻对准着这个方向。难道是格鲁希大胆地违背命令，奇迹般地及时赶到了？可是不！一个带上来的俘虏报告说，这是布吕歇尔将军的前卫部队，是普鲁士军队。此刻，皇帝第一次预感到，那支被击溃的普军为了抢先与英军会合，已摆脱了追击；而他——拿破仑自己却用了三分之一的兵力在空地上作毫无用处、失去目标的运动。他立即给格鲁希写了一封信，命令他不惜一切代价赶紧与自己靠拢，并阻止普军向威灵顿的战场集结。</p>
<p>与此同时，内伊元帅又接到了进攻的命令。必须在普军到达以前歼灭威灵顿部队。整个下午，向威灵顿的高地发起了一次又一次的冲锋。战斗一次比一次残酷，投入的步兵一次比一次多。但是威灵顿依旧岿然不动。而格鲁希那边却始终没有消息来。内伊元帅已决定把全部队伍都拉上去，决一死战。于是，1万名殊死一战的盔甲骑兵和步骑兵踩烂了英军的方阵，砍死了英军的炮手，冲破了英军的最初几道防线。虽然他们自己再次被迫撤退，但英军的战斗力已濒于殆尽。山头上像箍桶似的严密防线开始松散了。当受到重大伤亡的法军骑兵被炮火击退下来时，拿破仑的最后预备队——老近卫军正步履艰难地向山头进攻。欧洲的命运全系在能否攻占这一山头上。</p>
<p>决战</p>
<p>自上午以来，双方的400门大炮不停地轰击着。前线响彻骑兵队向开火的方阵冲杀的铁蹄声。从四面八方传来的冬冬战鼓声，震耳欲聋，整个平原都在颤动！但是在双方的山头上，双方的统帅似乎都听不见这嘈杂的人声。他们只是倾听着更为微弱的声音。</p>
<p>两只表在双方的统帅手中，像小鸟的心脏似的在嘀嗒嘀嗒地响。这轻轻的钟表声超过所有震天的吼叫声。拿破仑和威灵顿各自拿着自己的计时器，数着每一小时，每一分钟，计算着还有多少时间，最后的决定性的增援部队就该到达了。威灵顿知道布吕歇尔就在附近。而拿破仑则希望格鲁希也在附近。现在双方都已没有后备部队了。谁的增援部队先到，谁就赢得这次战役的胜利。</p>
<p>普军的侧翼终于响起了枪击声。拿破仑深深地吸了一口气：&#8220;格鲁希终于来了！&#8221;他以为自己的侧翼现在已有了保护，于是集中了最后剩下的全部兵力，向威灵顿的主阵地再次发起攻击。这主阵地就是布鲁塞尔的门闩，必须将它摧毁，这主阵地就是欧洲的大门，必须将它冲破。</p>
<p>然而刚才那一阵枪声仅仅是一场误会。由于汉诺威兵团穿着别样的军装，前来的普军向汉诺威士兵开了枪。但这场误会的遭遇战很快就停止了。现在，普军的大批人马毫无阻挡地、浩浩荡荡地从树林里穿出来。厄运就此降临了。这一消息飞快地在拿破仑的部队中传开。部队开始退却。所有剩下的英军一下子全都跃身而起，向着溃退的敌人冲去。与此同时，普鲁士骑兵也从侧面向仓皇逃窜、疲于奔命的法军冲杀过去。</p>
<p>仅仅几分钟的工夫，这支赫赫军威的部队变成了一股被人驱赶的抱头鼠窜、惊慌失措的人流。在一片惊恐的混乱叫喊声中，他们轻而易举地捕获了拿破仑的御用马车和全军的贵重财物，俘虏了全部炮兵。只是由于黑夜的降临，才拯救了拿破仑的性命和自由。一直到半夜，满身污垢、头昏目眩的拿破仑才在一家低矮的乡村客店里，疲倦地躺坐在扶手软椅上，这时，他已不再是个皇帝了。他的帝国、他的皇朝、他的命运全完了。一个微不足道的小人物的怯懦毁坏了他这个最有胆识、最有远见的人物在20年里所建立起来的全部英雄业绩。</p>
<p>那关键的一秒钟就是这样进行了可怕的报复。在尘世生活中，这样的一瞬间是很少降临的。当它无意之中降临到一个人身上时，他却不知如何利用它。在命运降临的伟大瞬间，市民的一切美德——小心、顺从、勤勉、谨慎，都无济于事，它始终只要求天才人物，并且将他造就成不朽的形象。命运鄙视地把畏首畏尾的人拒之门外。命运——这世上的另一位神，只愿意用热烈的双臂把勇敢者高高举起，送上英雄们的天堂。</p>
<img src ="http://www.cppblog.com/bloodsuck/aggbug/28261.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2007-07-18 10:42 <a href="http://www.cppblog.com/bloodsuck/archive/2007/07/18/28261.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>1个形式怪异的函数</title><link>http://www.cppblog.com/bloodsuck/archive/2007/06/12/26156.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Tue, 12 Jun 2007 08:09:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2007/06/12/26156.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/26156.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2007/06/12/26156.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/26156.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/26156.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;&nbsp;backarry(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;arrayname&nbsp;)[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">])&nbsp;)&nbsp;&nbsp;[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]<br></span><span style="COLOR: #008080">2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;arrayname;<br></span><span style="COLOR: #008080">4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>};</span></div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 呵呵，是有点古怪 <br><br>&nbsp; 再来个<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;&nbsp;backarry(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;arrayname&nbsp;)[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">])&nbsp;)&nbsp;&nbsp;[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;arrayname;<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>};<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">&nbsp;&nbsp;backarry(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">&nbsp;arrayname)[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]))[</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">]<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;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">3</span><span style="COLOR: #000000">;</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i)<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">i;<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;arrayname;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>};<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;main()<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">array</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">{</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>backarry(</span><span style="COLOR: #0000ff">array</span><span style="COLOR: #000000">);</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000">会调用哪个呢？？<br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}</span></div>
<img src ="http://www.cppblog.com/bloodsuck/aggbug/26156.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2007-06-12 16:09 <a href="http://www.cppblog.com/bloodsuck/archive/2007/06/12/26156.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个 Decorator 模式 例子（原）</title><link>http://www.cppblog.com/bloodsuck/archive/2007/03/22/20338.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Thu, 22 Mar 2007 01:56:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2007/03/22/20338.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/20338.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2007/03/22/20338.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/20338.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/20338.html</trackback:ping><description><![CDATA[
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span>
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#pragma once<br /></span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />class component<br /></span>
				<span style="COLOR: #008080"> 4</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080"> 5</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080"> 6</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    component(void);<br /></span>
				<span style="COLOR: #008080"> 7</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  virtual void printsefl()</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">   ;<br /></span>
				<span style="COLOR: #008080"> 8</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080"> 9</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    virtual ~component(void);<br /></span>
				<span style="COLOR: #008080">10</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />};<br /></span>
				<span style="COLOR: #008080">11</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">12</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />class concreatecom :</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> component<br /></span>
				<span style="COLOR: #008080">13</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">14</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080">15</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    concreatecom(char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> );<br /></span>
				<span style="COLOR: #008080">16</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  virtual void printsefl()   ;<br /></span>
				<span style="COLOR: #008080">17</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  virtual ~concreatecom(void);<br /></span>
				<span style="COLOR: #008080">18</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />protected:<br /></span>
				<span style="COLOR: #008080">19</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080">20</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />char </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> _psz_text;<br /></span>
				<span style="COLOR: #008080">21</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />};<br /></span>
				<span style="COLOR: #008080">22</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">23</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />class decorator:</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> component<br /></span>
				<span style="COLOR: #008080">24</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">25</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080">26</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />     decorator(component</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #008080">27</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  virtual void printsefl()     ;<br /></span>
				<span style="COLOR: #008080">28</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  virtual ~decorator();<br /></span>
				<span style="COLOR: #008080">29</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />protected:<br /></span>
				<span style="COLOR: #008080">30</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">31</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080">32</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   component </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> _pcomponent;<br /></span>
				<span style="COLOR: #008080">33</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />};<br /></span>
				<span style="COLOR: #008080">34</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />class  headdeco:</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> decorator<br /></span>
				<span style="COLOR: #008080">35</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">36</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080">37</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />       headdeco(component</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #008080">38</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   virtual void printsefl()   ;<br /></span>
				<span style="COLOR: #008080">39</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   virtual ~headdeco();<br /></span>
				<span style="COLOR: #008080">40</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />protected:<br /></span>
				<span style="COLOR: #008080">41</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    virtual void printhead()  ;<br /></span>
				<span style="COLOR: #008080">42</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080">43</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> _i_head;<br /></span>
				<span style="COLOR: #008080">44</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />};<br /></span>
				<span style="COLOR: #008080">45</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">46</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />class enddeco:</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> decorator<br /></span>
				<span style="COLOR: #008080">47</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">48</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080">49</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />      enddeco(component</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">,char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #008080">50</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    virtual void printsefl() ;<br /></span>
				<span style="COLOR: #008080">51</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    virtual  ~enddeco();<br /></span>
				<span style="COLOR: #008080">52</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />protected:<br /></span>
				<span style="COLOR: #008080">53</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />      virtual void printend() ;<br /></span>
				<span style="COLOR: #008080">54</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000">:<br /></span>
				<span style="COLOR: #008080">55</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> _pch_end;<br /></span>
				<span style="COLOR: #008080">56</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />};</span>
		</div>
		<br />
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span>
				<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">StdAfx.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<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 />
				</span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">component.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 4</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />using namespace std;<br /></span>
				<span style="COLOR: #008080"> 5</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 6</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />component::component(void)<br /></span>
				<span style="COLOR: #008080"> 7</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080"> 8</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080"> 9</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">10</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />component::~component(void)<br /></span>
				<span style="COLOR: #008080">11</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">12</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">13</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">14</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void concreatecom::printsefl() <br /></span>
				<span style="COLOR: #008080">15</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">16</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">endl;<br /></span>
				<span style="COLOR: #008080">17</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">_psz_text ;<br /></span>
				<span style="COLOR: #008080">18</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">endl;<br /></span>
				<span style="COLOR: #008080">19</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">20</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> concreatecom::concreatecom(char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> psz)<br /></span>
				<span style="COLOR: #008080">21</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">22</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />      _psz_text</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">psz;<br /></span>
				<span style="COLOR: #008080">23</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">24</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> decorator::decorator(component</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> a):<br /></span>
				<span style="COLOR: #008080">25</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   _pcomponent(a)<br /></span>
				<span style="COLOR: #008080">26</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">27</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  <br /></span>
				<span style="COLOR: #008080">28</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">29</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />concreatecom::~concreatecom()<br /></span>
				<span style="COLOR: #008080">30</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">31</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">32</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">33</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void decorator::printsefl()<br /></span>
				<span style="COLOR: #008080">34</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">35</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />_pcomponent.printsefl();<br /></span>
				<span style="COLOR: #008080">36</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    <br /></span>
				<span style="COLOR: #008080">37</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">38</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">39</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />decorator::~decorator()<br /></span>
				<span style="COLOR: #008080">40</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">41</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">42</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">43</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">44</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> headdeco::headdeco(component </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> refcom, </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i):<br /></span>
				<span style="COLOR: #008080">45</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  decorator(refcom)<br /></span>
				<span style="COLOR: #008080">46</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> ,_i_head(i)<br /></span>
				<span style="COLOR: #008080">47</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">48</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">49</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">50</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void headdeco::printsefl() <br /></span>
				<span style="COLOR: #008080">51</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{ <br /></span>
				<span style="COLOR: #008080">52</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   printhead();<br /></span>
				<span style="COLOR: #008080">53</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   decorator::printsefl();<br /></span>
				<span style="COLOR: #008080">54</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   <br /></span>
				<span style="COLOR: #008080">55</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">56</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void headdeco::printhead() <br /></span>
				<span style="COLOR: #008080">57</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">58</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">endl;<br /></span>
				<span style="COLOR: #008080">59</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">_i_head;<br /></span>
				<span style="COLOR: #008080">60</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">endl;<br /></span>
				<span style="COLOR: #008080">61</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">62</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />headdeco::~headdeco()<br /></span>
				<span style="COLOR: #008080">63</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">64</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> <br /></span>
				<span style="COLOR: #008080">65</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">66</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">67</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />enddeco::enddeco(component </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> refcom,char </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> pch)<br /></span>
				<span style="COLOR: #008080">68</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />:decorator(refcom)<br /></span>
				<span style="COLOR: #008080">69</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />,_pch_end(pch)<br /></span>
				<span style="COLOR: #008080">70</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">71</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   <br /></span>
				<span style="COLOR: #008080">72</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">73</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void enddeco::printsefl() <br /></span>
				<span style="COLOR: #008080">74</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">75</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    decorator::printsefl();<br /></span>
				<span style="COLOR: #008080">76</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    printend();<br /></span>
				<span style="COLOR: #008080">77</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">78</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />void enddeco::printend()  <br /></span>
				<span style="COLOR: #008080">79</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">80</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">endl;<br /></span>
				<span style="COLOR: #008080">81</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">_pch_end;<br /></span>
				<span style="COLOR: #008080">82</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    cout</span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000">endl;<br /></span>
				<span style="COLOR: #008080">83</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">84</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />enddeco::~enddeco()<br /></span>
				<span style="COLOR: #008080">85</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">86</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">87</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}</span>
		</div>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span>
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">//</span>
				<span style="COLOR: #000000"> decorator.cpp : 定义控制台应用程序的入口点。<br /></span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">//</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 4</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">stdafx.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 5</span>
				<span style="COLOR: #000000">
						<img src="http://www.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 />
				</span>
				<span style="COLOR: #008080"> 6</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">component.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 7</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />using namespace std;<br /></span>
				<span style="COLOR: #008080"> 8</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 9</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /> void printmodel(component</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> pcom )<br /></span>
				<span style="COLOR: #008080">10</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">11</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    pcom.printsefl();<br /></span>
				<span style="COLOR: #008080">12</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">13</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> _tmain(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc, _TCHAR</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> argv[])<br /></span>
				<span style="COLOR: #008080">14</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span>
				<span style="COLOR: #008080">15</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />     <br /></span>
				<span style="COLOR: #008080">16</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    printmodel(headdeco(headdeco(enddeco(concreatecom(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">正文输出中。。。。</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">黄大仙</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #000000">2</span>
				<span style="COLOR: #000000">),</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">));<br /></span>
				<span style="COLOR: #008080">17</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    return </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #008080">18</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span>
				<span style="COLOR: #008080">19</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<p>
				<br />
				<br />       这个decorator 模式例子让初学者 更能加深 多态威力的体会和 decorator 模式 比子类灵活的体会<br />要注意的问题是：对象链总是在 concreatecomponent  对象处结束。<br /><br />  ///此处是client 使用 对象的入口点，仅仅得到了 1个 decorator 的派生类对象，client 什么都不知道<br />printmodel(headdeco(headdeco(enddeco(concreatecom("正文输出中。。。。"),"黄大仙"),2),1));<br />///<br /></p>
		<p>     在vc2005 下通过<br /></p>
<img src ="http://www.cppblog.com/bloodsuck/aggbug/20338.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2007-03-22 09:56 <a href="http://www.cppblog.com/bloodsuck/archive/2007/03/22/20338.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>STL container  </title><link>http://www.cppblog.com/bloodsuck/archive/2006/09/18/12667.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Mon, 18 Sep 2006 02:43:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2006/09/18/12667.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/12667.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2006/09/18/12667.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/12667.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/12667.html</trackback:ping><description><![CDATA[    
<p>Containers in STL can be divided into three categories:<br />1.sequence containers,<br />2.associative containers,<br />3.container adapters. <br /><br />1.Sequence Containers</p><div class="section" id="sectionSection0" name="collapseableSection"><p>Sequence containers maintain the original ordering of inserted elements. This allows you to specify where to insert the element in the container.</p><p>The <b>deque</b> (double-ended queue) container allows for fast insertions and deletions at the beginning and end of the container. You can also randomly access any element quickly.</p><p>The <b>list</b> container allows for fast insertions and deletions anywhere in the container, but you cannot randomly access an element in the container.</p><p>The <b>vector</b> container behaves like an array, but will automatically grow as required.</p><p>For more information on the sequence containers, consult the following table:</p><div class="labelheading"><b></b></div><div class="tableSection"><table cellspacing="2" cellpadding="5" width="100%"><tbody><tr><th>Sequence Container </th><th>Native STL </th></tr><tr><td><p><b>deque</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/64842ee5-057a-4063-8c16-4267a0332584.htm"><font color="#002c99">deque Class</font></a></p></td></tr><tr><td><p><b>ilist</b></p></td><td><p>Not Applicable</p></td></tr><tr><td><p><b>list</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/d3707f4a-10fd-444f-b856-f9ca2077c1cd.htm"><font color="#002c99">list Class</font></a></p></td></tr><tr><td><p><b>vector</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/a3e0a8f8-7565-4fe0-93e4-e4d74ae1b70d.htm"><font color="#002c99">vector Class</font></a><br /></p></td></tr></tbody></table></div></div>2.Associative Containers 
<div class="section" id="sectionSection1" name="collapseableSection"><p>The defining characteristic of associative containers is that elements are inserted in a pre-defined order, such as sorted ascending.</p><p>The associative containers can be grouped into two subsets: maps and sets. A <b>map</b>, sometimes referred to as a dictionary, consists of a key/value pair. The key is used to order the sequence, and the value is somehow associated with that key. For example, a <b>map</b> might contain keys representing every unique word in a text and values representing the number of times that word appears in the text. A <b>set</b> is simply an ascending container of unique elements.</p><p>Both <b>map</b> and <b>set</b> only allow one instance of a key or element to be inserted into the container. If multiple instances of elements are required, use <b>multimap</b> or <b>multiset</b>.</p><p>Both maps and sets support bidirectional iterators. For more information on iterators, see <a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/2f746be7-b37d-4bfc-bf05-be4336ca982f.htm"><font color="#002c99">Iterators</font></a>.</p><p>While not officially part of the STL standard, <b>hash_map</b> and <b>hash_set</b> are commonly used to improve searching times. These containers store their elements as a hash table, with each table entry containing a bidirectional linked list of elements. To ensure the fastest search times, make sure that the hashing algorithm for your elements returns evenly distributed hash values.</p><p>For more information on the associative containers, consult the following table:</p><div class="labelheading"><b></b></div><div class="tableSection"><table cellspacing="2" cellpadding="5" width="100%"><tbody><tr><th>Associative Container </th><th>Native STL </th></tr><tr><td><p><b>hash_map</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/40879dfc-51ba-4a59-9f9e-26208de568a8.htm"><font color="#002c99">hash_map Class</font></a></p></td></tr><tr><td><p><b>hash_multimap</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/f41a6db9-67aa-43a3-a3c5-dbfe9ec3ae7d.htm"><font color="#002c99">hash_multimap Class</font></a></p></td></tr><tr><td><p><b>hash_multiset</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/0580397a-a76e-40ad-aea2-5c6f3a9d0a21.htm"><font color="#002c99">hash_multiset Class</font></a></p></td></tr><tr><td><p><b>hash_set</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/c765c06e-cbb6-48c2-93ca-d15468eb28d7.htm"><font color="#002c99">hash_set Class</font></a></p></td></tr><tr><td><p><b>map</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/7876f4c9-ebb4-4878-af1e-09364c43af0a.htm"><font color="#002c99">map Class</font></a></p></td></tr><tr><td><p><b>multimap</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/8796ae05-37c4-475a-9e61-75fde9d4a463.htm"><font color="#002c99">multimap Class</font></a></p></td></tr><tr><td><p><b>multiset</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/630e8c10-0ce9-4ad9-8d79-9e91a600713f.htm"><font color="#002c99">multiset Class</font></a></p></td></tr><tr><td><p><b>set</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/8991f9aa-5509-4440-adc1-371512d32018.htm"><font color="#002c99">set Class</font></a></p></td></tr></tbody></table></div></div><br /><br />3.Container Adapters 
<div class="section" id="sectionSection2" name="collapseableSection"><p>The container adapters are simply variations of the above containers. The container adapters do not support iterators.</p><p>The <b>priority_queue</b> container organized such that the element with the highest value is always first in the queue.</p><p>The <b>queue</b> container follows FIFO (first in, first out) semantics. The first element inserted (pushed) into the queue is the first to be removed (popped).</p><p>The <b>stack</b> container follows LIFO (last in, first out) semantics. The last element to be inserted (pushed) on the stack is the first element to be removed (popped).</p><p>Since container adapters do not support iterators, they cannot be used with the STL algorithms. For more information on algorithms, see <a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/dec9b373-7d5c-46cc-b7d2-21a938ecd0a6.htm"><font color="#002c99">Algorithms</font></a>.</p><p>For more information on the container adapters, consult the following table:</p><div class="labelheading"><b></b></div><div class="tableSection"><table cellspacing="2" cellpadding="5" width="100%"><tbody><tr><th>Container Adapter </th><th>Native STL </th></tr><tr><td><p><b>priority_queue</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/69fca9cc-a449-4be4-97b7-02ca5db9cbb2.htm"><font color="#002c99">priority_queue Class</font></a></p></td></tr><tr><td><p><b>queue</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/28c20ab0-3a72-4185-9e0f-5a44eea0e204.htm"><font color="#002c99">queue Class</font></a></p></td></tr><tr><td><p><b>stack</b></p></td><td><p><a href="ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_vcstdlib/html/02151c1e-eab0-41b8-be94-a839ead78ecf.htm"><font color="#002c99">stack Class</font></a></p></td></tr></tbody></table></div></div><br /><br /><br />Requirements for Container Elements 
<div class="section" id="sectionSection3" name="collapseableSection"><p>Elements inserted into an STL container can be of any object type that supplies a public copy constructor, a public <br />                                      public 拷贝构造 ，public 析构 ,public 赋值操作符   elem&amp; operator =( elem const &amp;)<br />destructor, and a public assignment operator. The destructor may not throw an exception. Furthermore, associative <br />                                                                       析构不能抛出异常<br />containers such as <b>set</b> and <b>map</b> must have a public comparison operator defined, which is operator&lt; by default. Some <br />                             关联容器  除此外 还应由有 比较操作符<br />                  operations on containers might also require a public default constructor and a public equivalence operator.<br /><br /><br /><br /><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"><span style="COLOR: #008080"> 1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">list</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">deque</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">map</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><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 /></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">typename inputitrator </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> predict(inputitrator  a)<br /></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img id="Codehighlighter1_166_267_Open_Image" onclick="this.style.display='none'; Codehighlighter1_166_267_Open_Text.style.display='none'; Codehighlighter1_166_267_Closed_Image.style.display='inline'; Codehighlighter1_166_267_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_166_267_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_166_267_Closed_Text.style.display='none'; Codehighlighter1_166_267_Open_Image.style.display='inline'; Codehighlighter1_166_267_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_166_267_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_166_267_Open_Text"><span style="COLOR: #000000">{   iterator_traits</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">inputitrator</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterato_category  b;<br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   <br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> endl</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">  </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">typeid(b).name();<br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />main()<br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img id="Codehighlighter1_279_479_Open_Image" onclick="this.style.display='none'; Codehighlighter1_279_479_Open_Text.style.display='none'; Codehighlighter1_279_479_Closed_Image.style.display='inline'; Codehighlighter1_279_479_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_279_479_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_279_479_Closed_Text.style.display='none'; Codehighlighter1_279_479_Open_Image.style.display='inline'; Codehighlighter1_279_479_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_279_479_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_279_479_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> a;<br /></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  deque</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> b;<br /></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  list</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> c;<br /></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> d;<br /></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> e;<br /></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  <br /></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   predict(a.begin());<br /></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   predict(b.begin());<br /></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />   predict(c.begin());<br /></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    predict(d.begin());<br /></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     predict(e.begin());<br /></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div></div><pre>output iterator
   -&gt; forward iterator
   -&gt; bidirectional iterator
   -&gt; random-access iterator<br /><br /><pre>input iterator
   -&gt; forward iterator
   -&gt; bidirectional iterator
   -&gt; random-access iterator</pre></pre><img src ="http://www.cppblog.com/bloodsuck/aggbug/12667.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2006-09-18 10:43 <a href="http://www.cppblog.com/bloodsuck/archive/2006/09/18/12667.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC 中 命令消息传递 （原创）</title><link>http://www.cppblog.com/bloodsuck/archive/2006/07/27/10575.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Thu, 27 Jul 2006 03:27:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2006/07/27/10575.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/10575.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2006/07/27/10575.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/10575.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/10575.html</trackback:ping><description><![CDATA[                        先对对于mfc中的命令消息路由的机制原理作个简单的总结：<br />      CCmdTarget 为 模板 ，提供： CCmdTarget::OnCmdMsg() 这个函数 对 其派生类 的消息结构数组（它是静态的）做搜索 并向上（基类）的结构数组做搜索并调用相应的成员函数。<br />   派生类使用 <br /> DECLARE_MESSAGE_MAP()<br />BEGIN_MESSAGE_MAP(本类, 基类)<br /> ON_COMMAND(ID_APP_ABOUT, OnAppAbout)<br />END_MESSAGE_MAP()<br />加入链表<br /><br />        AfxWndProc （只有发向窗口才会被调用），此函数 将使用HWND 在 mfc库的全局变量中<br />找到句柄映射表，转为 CWnd 型 ，最终使用 派生类的对OnCmdMsg()的重载 来实现 不同的路由<br /><br />     以上原理<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"><span style="COLOR: #008080"> 1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> CMan : </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> CCmdTarget<br /></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img id="Codehighlighter1_31_284_Open_Image" onclick="this.style.display='none'; Codehighlighter1_31_284_Open_Text.style.display='none'; Codehighlighter1_31_284_Closed_Image.style.display='inline'; Codehighlighter1_31_284_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_31_284_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_31_284_Closed_Text.style.display='none'; Codehighlighter1_31_284_Open_Image.style.display='inline'; Codehighlighter1_31_284_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_31_284_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_31_284_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    DECLARE_DYNAMIC(CMan)<br /></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    CMan();<br /></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">~</span><span style="COLOR: #000000">CMan();<br /></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    DECLARE_MESSAGE_MAP()<br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    afx_msg </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> OnAppAbout();<br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000"> BOOL OnCmdMsg(UINT nID, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nCode, </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pExtra, AFX_CMDHANDLERINFO</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pHandlerInfo);<br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> m_id;<br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    CString m_name;<br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img id="Codehighlighter1_286_357_Open_Image" onclick="this.style.display='none'; Codehighlighter1_286_357_Open_Text.style.display='none'; Codehighlighter1_286_357_Closed_Image.style.display='inline'; Codehighlighter1_286_357_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_286_357_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_286_357_Closed_Text.style.display='none'; Codehighlighter1_286_357_Open_Image.style.display='inline'; Codehighlighter1_286_357_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />}</span></span><span style="COLOR: #000000">;</span><span id="Codehighlighter1_286_357_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_286_357_Open_Text"><span style="COLOR: #808080">////////////</span><span style="COLOR: #008000">自定义的c++类<br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">18</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">19</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span><span style="COLOR: #808080">///////////////</span><span style="COLOR: #008000">/重载 onCmdMsg，（m_man为CMainFram的成员）</span><span style="COLOR: #808080"></span></span><br /><span style="COLOR: #008080">20</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">BOOL CMainFrame::OnCmdMsg(UINT nID, </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nCode, </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pExtra, AFX_CMDHANDLERINFO</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> pHandlerInfo)<br /></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img id="Codehighlighter1_453_656_Open_Image" onclick="this.style.display='none'; Codehighlighter1_453_656_Open_Text.style.display='none'; Codehighlighter1_453_656_Closed_Image.style.display='inline'; Codehighlighter1_453_656_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_453_656_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_453_656_Closed_Text.style.display='none'; Codehighlighter1_453_656_Open_Image.style.display='inline'; Codehighlighter1_453_656_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_453_656_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_453_656_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: 在此添加专用代码和/或调用基类</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">23</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">          </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (m_man.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo ))<br /></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img id="Codehighlighter1_556_587_Open_Image" onclick="this.style.display='none'; Codehighlighter1_556_587_Open_Text.style.display='none'; Codehighlighter1_556_587_Closed_Image.style.display='inline'; Codehighlighter1_556_587_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_556_587_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_556_587_Closed_Text.style.display='none'; Codehighlighter1_556_587_Open_Image.style.display='inline'; Codehighlighter1_556_587_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />          </span><span id="Codehighlighter1_556_587_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_556_587_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />              </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />          }</span></span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);<br /></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img id="Codehighlighter1_658_684_Open_Image" onclick="this.style.display='none'; Codehighlighter1_658_684_Open_Text.style.display='none'; Codehighlighter1_658_684_Closed_Image.style.display='inline'; Codehighlighter1_658_684_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_658_684_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_658_684_Closed_Text.style.display='none'; Codehighlighter1_658_684_Open_Image.style.display='inline'; Codehighlighter1_658_684_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_658_684_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_658_684_Open_Text"><span style="COLOR: #808080">////////////</span><span style="COLOR: #008000">//给CMan 加个命令响应</span><span style="COLOR: #808080"></span></span><br /><span style="COLOR: #008080">31</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">BEGIN_MESSAGE_MAP(CMan, CCmdTarget)<br /></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    ON_COMMAND(ID_APP_ABOUT, OnAppAbout)<br /></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />END_MESSAGE_MAP()<br /></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> CMan 消息处理程序</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">38</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> CMan::OnAppAbout()<br /></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img id="Codehighlighter1_820_919_Open_Image" onclick="this.style.display='none'; Codehighlighter1_820_919_Open_Text.style.display='none'; Codehighlighter1_820_919_Closed_Image.style.display='inline'; Codehighlighter1_820_919_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_820_919_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_820_919_Closed_Text.style.display='none'; Codehighlighter1_820_919_Open_Image.style.display='inline'; Codehighlighter1_820_919_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_820_919_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_820_919_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> TODO: 在此添加命令处理程序代码</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">42</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">    CString str;<br /></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    str.Format(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,m_id);<br /></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    str</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">m_name;<br /></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    AfxMessageBox(str);<br /></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img id="Codehighlighter1_921_932_Open_Image" onclick="this.style.display='none'; Codehighlighter1_921_932_Open_Text.style.display='none'; Codehighlighter1_921_932_Closed_Image.style.display='inline'; Codehighlighter1_921_932_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_921_932_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_921_932_Closed_Text.style.display='none'; Codehighlighter1_921_932_Open_Image.style.display='inline'; Codehighlighter1_921_932_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_921_932_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_921_932_Open_Text"><span style="COLOR: #808080">/////////</span><span style="COLOR: #008000">//</span><span style="COLOR: #808080"></span></span><br /><span style="COLOR: #008080">48</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />运行后就会发现 此命令将由CMan::onAppAbout() 来 <br /></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />响应</span></div><img src ="http://www.cppblog.com/bloodsuck/aggbug/10575.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2006-07-27 11:27 <a href="http://www.cppblog.com/bloodsuck/archive/2006/07/27/10575.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>聚合</title><link>http://www.cppblog.com/bloodsuck/archive/2006/07/05/9422.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Wed, 05 Jul 2006 03:45:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2006/07/05/9422.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/9422.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2006/07/05/9422.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/9422.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/9422.html</trackback:ping><description><![CDATA[            重用的另一种方法<br />      a 聚合 b<br />    b 要有必要的支持才能实现，具体过程如：<br />     a, cocreateinstance,指定 自己的IUnknown  ,并必须在iid,ppv中指定是 IID__IUnknown ,IUnknown*（被聚合的com类的 非委托IUnknown）<br />此时 被聚合类 在类厂（createinstance 中 接收 a的 IUnknown  并在 b 的成员中赋好值）支持下，被创建<br />的com类 被创建。<br />      b 中 2组 IUnknown 接口：委托（聚合） 和   非委托（正常）<br />    在a 中获取 IUnknown接口（b的），请求 其他 接口时 ( a把 客户发出的对b 的接口请求 转到  a 获取<br /> IUnknown 接口 调用 queryinterface ),全部使用  b 对象 的  委托接口  来判断  是把接口请求 转到 <br />非委托 还是 外部  a 的IUnknown<br /><img src ="http://www.cppblog.com/bloodsuck/aggbug/9422.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2006-07-05 11:45 <a href="http://www.cppblog.com/bloodsuck/archive/2006/07/05/9422.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个包容重用</title><link>http://www.cppblog.com/bloodsuck/archive/2006/07/04/9383.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Tue, 04 Jul 2006 08:20:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2006/07/04/9383.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/9383.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2006/07/04/9383.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/9383.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/9383.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1								#pragma once				  2																		static				 				const				 GUID CLSID_mydiv 				=				 				  3																																												{ 			...&nbsp;&nbsp;<a href='http://www.cppblog.com/bloodsuck/archive/2006/07/04/9383.html'>阅读全文</a><img src ="http://www.cppblog.com/bloodsuck/aggbug/9383.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2006-07-04 16:20 <a href="http://www.cppblog.com/bloodsuck/archive/2006/07/04/9383.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Run time type Information</title><link>http://www.cppblog.com/bloodsuck/archive/2006/07/04/9360.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Tue, 04 Jul 2006 02:23:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2006/07/04/9360.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/9360.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2006/07/04/9360.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/9360.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/9360.html</trackback:ping><description><![CDATA[
		<dd>
				<b>
						<br />一                 dynamic_cast</b>
				<b>&lt;</b>
				<i> type-id</i>
				<b> &gt;</b>
				<b>(</b>
				<i>expression </i>
				<b>)</b>
				<br />  type-id :必须是指针或者引用<br />  expression:必须是指针或者一个左值<br />基本上是用来做 子对象间的转换<br />1.基本的用法<br /><pre class="code">class B { ... };
class C : public B { ... };
class D : public C { ... };

void f(D* pd)
{
   C* pc = dynamic_cast&lt;C*&gt;(pd);   // ok: C is a direct base class
                                 // pc points to C subobject of pd 

   B* pb = dynamic_cast&lt;B*&gt;(pd);   // ok: B is an indirect base class
                                 // pb points to B subobject of pd 
   ...
}</pre><p>This type of conversion is called an "upcast" because it moves a pointer up a class hierarchy, from a derived class to a class it is derived from. An upcast is an implicit conversion.</p><p>If <i>type-id</i> is void*, a run-time check is made to determine the actual type of <i>expression</i>. The result is a pointer to the complete object pointed to by <i>expression</i>. For example:</p><pre class="code">class A { ... };

class B { ... };

void f()
{
   A* pa = new A;
   B* pb = new B;
   void* pv = dynamic_cast&lt;void*&gt;(pa);
   // pv now points to an object of type A
   ...
   pv = dynamic_cast&lt;void*&gt;(pb);
   // pv now points to an object of type B
}</pre><p>If <i>type-id</i> is not void*, a run-time check is made to see if the object pointed to by <i>expression</i> can be converted to the type pointed to by <i>type-id</i>.</p><p>If the type of <i>expression</i> is a base class of the type of <i>type-id</i>, a run-time check is made to see if <i>expression</i> actually points to a complete object of the type of <i>type-id</i>. If this is true, the result is a pointer to a complete object of the type of <i>type-id</i>. For example:</p><pre class="code">class B { ... };
class D : public B { ... };

void f()
{
   B* pb = new D;                     // unclear but ok
   B* pb2 = new B;

   D* pd = dynamic_cast&lt;D*&gt;(pb);      // ok: pb actually points to a D
   ...
   D* pd2 = dynamic_cast&lt;D*&gt;(pb2);   // pb2 points to a B not a D
                                    // cast was bad so pd2 == NULL
   ...
}</pre><p>This type of conversion is called a "downcast" because it moves a pointer down a class hierarchy, from a given class to a class derived from it.<br />小结：<br />  a     实际指向对象 和   b 目标对象,  b 是a 的 基类（子对象），或者是2者 同级转换才成功<br />否则 目标为NULL;也就是说不能向下转<br /><br /><br /><br />2   多重非虚的继承模式<br /><br /></p><p class="label"><b>Class Hierarchy Showing Multiple Inheritance</b></p><p class="fig"><img alt="" src="ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vclang/html/vc39011.gif" border="0" /></p><p>A pointer to an object of type <code class="ce">D</code> can be safely cast to <code class="ce">B</code> or <code class="ce">C</code>. However, if <code class="ce">D</code> is cast to point to an <code class="ce">A</code> object, which instance of <code class="ce">A</code> would result? This would result in an ambiguous casting error. To get around this problem, you can perform two unambiguous casts. For example:</p><pre class="code">void f()
{
   D* pd = new D;
   A* pa = dynamic_cast&lt;A*&gt;(pd);      // error: ambiguous
   B* pb = dynamic_cast&lt;B*&gt;(pd);      // first cast to B
   A* pa2 = dynamic_cast&lt;A*&gt;(pb);   // ok: unambiguous
}</pre><p>Further ambiguities can be introduced when you use virtual base classes. Consider the class hierarchy shown in the following figure.</p><p>    也就是说在2意性下会失败<br />3.子对象间的转换<br /></p><p class="label"><b>Class Hierarchy Showing Duplicate Base Classes</b></p><p class="fig"><img alt="" src="ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vclang/html/vc39013.gif" border="0" /><br />    //pd 指向 e 对象<br />void f(D* pd)<br />{<br />   E* pe = dynamic_cast&lt;E*&gt;(pd);<br />   B* pb = pe;      // upcast, implicit conversion<br />   A* pa = pb;      // upcast, implicit conversion<br />}<br /><br />//pd 指向 e 对象<br />void f(D* pd)<br />{<br />   B* pb = dynamic_cast&lt;B*&gt;(pd);      // cross cast<br />   A* pa = pb;                  // upcast, implicit conversion<br />}<br /><br />  也就是  所谓 cross cast <br /><br />二  <b>typeid( </b><i>type-id</i><b> )     </b><b>typeid( </b><i>expression</i><b> )</b> <br />   此操作符返回个  const type_info &amp; <br />            expression 必须指向一个多态类型（带虚函数    ），并且要解引用<br /><br />#include &lt;iostream&gt;<br />#include &lt;typeinfo.h&gt;</p></dd>
		<dd>
				<p class="fig">class Base {<br />public:<br />   virtual void vvfunc() {}<br />};</p>
		</dd>
		<dd>
				<p class="fig">class Derived : public Base {};</p>
		</dd>
		<dd>
				<p class="fig">using namespace std;<br />int main()<br />{<br />   Derived* pd = new Derived;<br />   Base* pb = pd;<br />   cout &lt;&lt; typeid( pb ).name() &lt;&lt; endl;   //prints "class Base *"<br />   cout &lt;&lt; typeid( *pb ).name() &lt;&lt; endl;   //prints "class Derived"<br />   cout &lt;&lt; typeid( pd ).name() &lt;&lt; endl;   //prints "class Derived *"<br />   cout &lt;&lt; typeid( *pd ).name() &lt;&lt; endl;   //prints "class Derived"<br />   delete pd;<br />}<br />// compile with: /GR /EHsc<br /><br />在模版中使用<br />template &lt; typename T &gt; T max( T arg1, T arg2 ) {<br />   cout &lt;&lt; typeid( T ).name() &lt;&lt; "s compared." &lt;&lt; endl;<br />   return ( arg1 &gt; arg2 ? arg1 : arg2 );<br />}<br /><br /><br />            </p>
		</dd>
<img src ="http://www.cppblog.com/bloodsuck/aggbug/9360.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2006-07-04 10:23 <a href="http://www.cppblog.com/bloodsuck/archive/2006/07/04/9360.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个com组件的练习</title><link>http://www.cppblog.com/bloodsuck/archive/2006/06/30/9244.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Fri, 30 Jun 2006 09:23:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2006/06/30/9244.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/9244.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2006/06/30/9244.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/9244.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/9244.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: //				 {7B55D765-68A6-404e-99E2-CA9ABC389A27}																								static				 				const				  GUID IID_IUnknown9				=				 																								{ 						0x7b55d765...&nbsp;&nbsp;<a href='http://www.cppblog.com/bloodsuck/archive/2006/06/30/9244.html'>阅读全文</a><img src ="http://www.cppblog.com/bloodsuck/aggbug/9244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2006-06-30 17:23 <a href="http://www.cppblog.com/bloodsuck/archive/2006/06/30/9244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC中 windows object 和 C++ object</title><link>http://www.cppblog.com/bloodsuck/archive/2006/06/30/9222.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Fri, 30 Jun 2006 03:33:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2006/06/30/9222.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/9222.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2006/06/30/9222.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/9222.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/9222.html</trackback:ping><description><![CDATA[
		<p class="label">
				<b>The Problem</b>
		</p>
		<p>Windows objects are normally represented by <b>HANDLE</b>s. The MFC classes wrap Windows object handles with C++ objects. The handle wrapping functions of the MFC class library provide a way to find the C++ object that is wrapping the Windows object with a particular handle. There are times when a Windows object does not have a C++ wrapper object, however, and at these times a temporary object is created to act as the C++ wrapper.<br /></p>
		<p>mfc 映射的 windows object ----&gt;c++ wrapper<br />以下使用 mfc 的函数 如：fromhandle, getdlgitem,都会返回temporary 和 pemanent  c++ wrapper object<br /> 注意：<br />     零时的 对象 会被在空闲时(<strong>OnIdle()函数)</strong>被删除，不能存下在下次消息处理中 使用<br />The default <b>OnIdle</b> processing in <b>CWinThread</b> automatically calls <b>DeleteTempMap</b> for each class that supports temporary handle maps<br />////////////////////////////////////////////////////////////<br />The Windows objects that use handle maps are: 
</p>
		<ul type="disc">
				<li>
						<b>HWND</b> (<b>CWnd</b> and <b>CWnd</b>-derived classes) 
</li>
				<li>
						<b>HDC</b> (<b>CDC</b> and <b>CDC</b>-derived classes) 
</li>
				<li>
						<b>HMENU</b> (<b>CMenu</b>) 
</li>
				<li>
						<b>HPEN</b> (<b>CGdiObject</b>) 
</li>
				<li>
						<b>HBRUSH</b> (<b>CGdiObject</b>) 
</li>
				<li>
						<b>HFONT</b> (<b>CGdiObject</b>) 
</li>
				<li>
						<b>HBITMAP</b> (<b>CGdiObject</b>) 
</li>
				<li>
						<b>HPALETTE</b> (<b>CGdiObject</b>) 
</li>
				<li>
						<b>HRGN</b> (<b>CGdiObject</b>) 
</li>
				<li>
						<b>HIMAGELIST</b> (<b>CImageList</b>) 
</li>
				<li>
						<b>SOCKET</b> (<b>CSocket</b>) </li>
		</ul>
		<p>///////////////////////////////////////////////</p>
		<p>Given a handle to any of these objects, you can find the MFC object that wraps the handle by calling the static member function <b>FromHandle</b>. For example, given an <b>HWND</b> called <i>hWnd</i>:</p>
		<pre class="code">CWnd::FromHandle(hWnd)</pre>
		<p>will return a pointer to the <b>CWnd</b> that wraps the <i>hWnd</i>. If that <i>hWnd</i> does not have a specific wrapper object, then a temporary <b>CWnd</b> is created to wrap the <b>hWnd</b>. This makes it possible to get a valid C++ object from any handle.</p>
		<p>Once you have a wrapper object, you can get to its handle through a public member variable. In the case of a <b>CWnd</b>, <i>m_hWnd</i> contains the <b>HWND</b> for that object.</p>
		<p class="label">
				<b>Attaching Handles to MFC Objects</b>
		</p>
		<p>Given a newly created handle-wrapper object and a handle to a Windows object, you can associate the two by calling <b>Attach</b>. For example:</p>
		<pre class="code">CWnd myWnd;
myWnd.Attach(hWnd);<br />  ////mywnd 析构时会调用 destroywindow ,连同 hwnd 一起销毁<br /><br /><br /><br /><br /></pre>
		<p>This makes an entry in the permanent map associating <i>myWnd</i> and <i>hWnd</i>. <br />Calling <b>CWnd::FromHandle</b>(<i>hWnd</i>) will now return a pointer to <i>myWnd</i>. <br />When <i>myWnd</i> is deleted, the destructor will automatically destroy the hWnd by calling the Windows <b>DestroyWindow</b> function. If this is not desired, the <i>hWnd</i> must be detached from <i>myWnd</i> before the <i>myWnd</i> object is destroyed (normally when leaving the scope at which <i>myWnd</i> was defined). The <b>Detach</b> member function does this.</p>
		<pre class="code">myWnd.Detach();</pre>
		<p class="label">
				<b>More About Temporary Objects</b>
		</p>
		<p>Temporary objects are created whenever <b>FromHandle</b> is given a handle that does not already have a wrapper object. These temporary objects are detached from their handle and deleted by the <b>DeleteTempMap</b> functions. The default <b>OnIdle</b> processing in <b>CWinThread</b> automatically calls <b>DeleteTempMap</b> for each class that supports temporary handle maps. This means that you cannot assume a pointer to a temporary object will be valid past the point of exit from the function where the pointer was obtained, as the temporary object will be deleted during the Windows message-loop idle time.</p>
		<p class="label">
				<b>很重要:<br />在多线程中传递 c++ wrapper object 是无效的(无论是 temporary 还是 permanent)<br />只能传递 windows handle, 换句话就是说， 线程 只能 访问 自己创建的c++ wrapper object<br /><br />Wrapper Objects and Multiple Threads</b>
		</p>
		<p>
				<font color="#ff0000">Both temporary and permanent objects are maintained on a per-thread basis. That is, one thread cannot access another threads C++ wrapper objects, regardless of whether it is temporary or permanent. As stated above, temporary objects are deleted when the thread which that temporary object belongs enters <b>OnIdle</b>.</font>
		</p>
		<p>
				<font color="#ff0000">To pass these objects from one thread to another, always send them as their native <b>HANDLE</b> type. Passing a C++ wrapper object from one thread to another will often result in unexpected results.</font>
		</p>
		<p>
				<font color="#ff0000">     </font>
		</p>
<img src ="http://www.cppblog.com/bloodsuck/aggbug/9222.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/bloodsuck/" target="_blank">黄大仙</a> 2006-06-30 11:33 <a href="http://www.cppblog.com/bloodsuck/archive/2006/06/30/9222.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>STL 乱学二（原创）</title><link>http://www.cppblog.com/bloodsuck/archive/2006/06/02/8084.html</link><dc:creator>黄大仙</dc:creator><author>黄大仙</author><pubDate>Fri, 02 Jun 2006 07:43:00 GMT</pubDate><guid>http://www.cppblog.com/bloodsuck/archive/2006/06/02/8084.html</guid><wfw:comment>http://www.cppblog.com/bloodsuck/comments/8084.html</wfw:comment><comments>http://www.cppblog.com/bloodsuck/archive/2006/06/02/8084.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/bloodsuck/comments/commentRss/8084.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/bloodsuck/services/trackbacks/8084.html</trackback:ping><description><![CDATA[1.容器<br />   顺序: vector(类似动态增长数组）  deque （双端队列）  list（双头指针）<br />   关联:set  multiset(有重复）  map   multiset（有重复） ，自动排序（内部2叉树）<br />  特殊预定义容器：stack, queue ,prority queue<br />2.迭代器<br />      每种容器都提供了自己的迭代器，相同的操作界面，不同的内部实现，<br />   *,-&gt;,==,!=,++,--共同操作<br />     随机iterator : 支持 &gt;，&lt;:如：vector, deque,string<br />    双向iterator:不支持&gt;,&lt;:<br />   特殊预定义：<br />插入迭代器<br />          insert iterator:引起自动增长，非覆盖<br />             back_inserter(container)<br />             front_inserter(container)<br />           inserter(container,pos)//调用 container.insert()//每种容器都具有insert()//关联容器唯一<br /> 流迭代器<br />             istream_iterator<br />             ostream_iterator<br /> 逆向迭代器<br />容器中元素应满足：<br />     有拷贝构造，赋值运算符，析构能销毁<br />   顺序：默认构造应该可用<br />   关联：必须有排序准则<br />容器中是 值不是引用<br /><br />通用操作：<br />   containertype c;<br />  ct  c(c1);<br />  ct   c(begin,end);<br /> c.~ct();<br /> c.size(), c.max_size(),c.empty(),c1==c2;c1&lt;c2;c1.swap(c2); swap(c1,c2);c.begin();c.end();c.rbegin();c.rend();<br />c.inert(pos,elem);c.erase(begin,end),c.clear(),c.get_allocator<br /> <br />     3.vector <br />    动态增长数组,在队尾插入，删除效率高<br />注意 动态增长时 迭代器失效 内部可能要重配置<br />除了clear(),vector 不会自动缩小<br />vector 的迭代器 就是 元素的native指针,连续存储，迭代器是个random <br />空判断<br />       a.begin==a.end<br /><br />4.list <br />   迭代器是个双向的，非连续存储，而且是个环状链表在尾端是个未初始化节点<br />空判断<br />   a.begin==a.end;<br />clear  remove  unique(把相同元素移出，留一个)  insert<br />只能使用成员函数 sort，不能使用 算法 sort(他只接受random iterator)<br />5 .deque<br />动态增长的双端队列 ，但内部机制和vector 不一样 ，若干连续存储的集合<br />算法复杂度高，如排序时可将 其复制到 vector中，头/尾插入/删除效率高  ，<br />提供随机迭代器<br />6.stack (container adapter)<br />先进后出，不供迭代器， 不提供走访功能<br />7.queue(container adapter)<br />  先进先出，不提供迭代器，不提供走访功能<br />8.heap 辅助<br />   其内部为一个完全2叉树，插入时自动排序，一般为max_heap<br />   左右无序，某节点 i, 父节点 i/2,左子节点 2i，右子节点 2i+1；<br /> <pre class="syntax"><b>template&lt;class RandomAccessIterator&gt; inline</b><b>   void make_heap(</b><b>      RandomAccessIterator </b><i>First</i><b>,</b><b>      RandomAccessIterator </b><i>Last</i><b>   )</b><b>template&lt;class RandomAccessIterator&gt; inline</b><b>   void sort_heap(</b><b>      RandomAccessIterator </b><i>First</i><b>,</b><b>      RandomAccessIterator </b><i>Last</i><b>   )</b><b>template&lt;class RandomAccessIterator&gt; inline</b><b>   void push_heap(</b><b>      RandomAccessIterator </b><i>First</i><b>,</b><b>      RandomAccessIterator </b><i>Last</i><b>   )</b><b>template&lt;class RandomAccessIterator&gt; inline</b><b>   void pop_heap(</b><b>      RandomAccessIterator </b><i>First</i><b>,</b><b>      RandomAccessIterator </b><i>Last</i><b>   )</b></pre>         <br />             9.set,关联容器 ，底层以rb-tree 实现，其迭代器为个const iterator<br />   不能用迭代器来改变 元