﻿<?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++博客-Good Good code,Day Day up-随笔分类-C++ </title><link>http://www.cppblog.com/dawnbreak/category/9034.html</link><description>PearLi's Blog</description><language>zh-cn</language><lastBuildDate>Mon, 25 Oct 2010 15:46:06 GMT</lastBuildDate><pubDate>Mon, 25 Oct 2010 15:46:06 GMT</pubDate><ttl>60</ttl><item><title>MSVC++ 对象内存模型深入解析与具体应用 (三)</title><link>http://www.cppblog.com/dawnbreak/archive/2010/06/05/117144.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Sat, 05 Jun 2010 06:13:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2010/06/05/117144.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/117144.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2010/06/05/117144.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/117144.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/117144.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MSVC++&nbsp;对象内存模型深入解析与具体应用前言：本文之所以强调MSVC,&nbsp;旨在提醒读者在不同平台和解释器下内存布局和实现上存在差异，但编程思想通用，文中内容大多来自笔者实际工作经验和网上搜集，力求正确，但水平有限，如有不当之处，敬请指出面向对象：本文面向有一定C/C++基础，并且可以读懂部分汇编的读者版权：欢迎转载，但请注明出处http://www.cppblog.com...&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2010/06/05/117144.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/117144.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2010-06-05 14:13 <a href="http://www.cppblog.com/dawnbreak/archive/2010/06/05/117144.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>从小函数实现看应聘者的编程素质（atoi.strcmp...）</title><link>http://www.cppblog.com/dawnbreak/archive/2009/08/24/94262.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Mon, 24 Aug 2009 07:17:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/08/24/94262.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/94262.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/08/24/94262.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/94262.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/94262.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/08/24/94262.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/94262.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-08-24 15:17 <a href="http://www.cppblog.com/dawnbreak/archive/2009/08/24/94262.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>A*算法实现</title><link>http://www.cppblog.com/dawnbreak/archive/2009/08/14/93351.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Fri, 14 Aug 2009 09:43:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/08/14/93351.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/93351.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/08/14/93351.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/93351.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/93351.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 根据前一篇文章描述实现的A*算法&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/08/14/93351.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/93351.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-08-14 17:43 <a href="http://www.cppblog.com/dawnbreak/archive/2009/08/14/93351.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>简版 容器vector 实现</title><link>http://www.cppblog.com/dawnbreak/archive/2009/08/12/93030.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Wed, 12 Aug 2009 07:46:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/08/12/93030.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/93030.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/08/12/93030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/93030.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/93030.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: vector为我们提供了可伸缩的顺序存储容器，在顺序和随机存储方面效率很高&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/08/12/93030.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/93030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-08-12 15:46 <a href="http://www.cppblog.com/dawnbreak/archive/2009/08/12/93030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>0-1背包问题</title><link>http://www.cppblog.com/dawnbreak/archive/2009/08/11/92854.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Mon, 10 Aug 2009 19:02:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/08/11/92854.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/92854.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/08/11/92854.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/92854.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/92854.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 0-1背包问题是对空间问题，排布选择问题的抽象&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/08/11/92854.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/92854.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-08-11 03:02 <a href="http://www.cppblog.com/dawnbreak/archive/2009/08/11/92854.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>八皇后问题一解--用几何方法简化编程问题</title><link>http://www.cppblog.com/dawnbreak/archive/2009/08/10/92813.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Mon, 10 Aug 2009 07:11:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/08/10/92813.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/92813.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/08/10/92813.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/92813.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/92813.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在一个8×8国际象棋盘上，有8个皇后，每个皇后占一格；要求皇后间不会出现相互“攻击”的现象，即不能有两个皇后处在同一行、同一列或同一对角线上。问共有多少种不同的方法。<br>&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/08/10/92813.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/92813.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-08-10 15:11 <a href="http://www.cppblog.com/dawnbreak/archive/2009/08/10/92813.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>写了一个关闭电脑屏幕的服务程序</title><link>http://www.cppblog.com/dawnbreak/archive/2009/07/15/90133.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Wed, 15 Jul 2009 06:36:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/07/15/90133.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/90133.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/07/15/90133.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/90133.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/90133.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 事情起因是这几天用电驴上下载一个资源，顺便推荐一下-国家地理频道的《终极工厂》，本人很喜欢看,偶然间翻到了http://www.verycd.com/topics/2746798/<br>总大小17多G，只好挂机下载，但是我XPS1530竟然没有关闭屏幕的热键-郁闷，盒上盖散热又是问题，那就自己动手吧<br>&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/07/15/90133.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/90133.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-07-15 14:36 <a href="http://www.cppblog.com/dawnbreak/archive/2009/07/15/90133.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用之前写的物理模拟引擎编写了个小游戏</title><link>http://www.cppblog.com/dawnbreak/archive/2009/06/05/86827.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Fri, 05 Jun 2009 03:14:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/06/05/86827.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/86827.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/06/05/86827.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/86827.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/86827.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/06/05/86827.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/86827.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-06-05 11:14 <a href="http://www.cppblog.com/dawnbreak/archive/2009/06/05/86827.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vc也搞for each</title><link>http://www.cppblog.com/dawnbreak/archive/2009/05/15/83066.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Fri, 15 May 2009 10:40:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/05/15/83066.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/83066.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/05/15/83066.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/83066.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/83066.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/05/15/83066.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/83066.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-05-15 18:40 <a href="http://www.cppblog.com/dawnbreak/archive/2009/05/15/83066.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对象与对象的类型信息----获取对象的RTTI信息</title><link>http://www.cppblog.com/dawnbreak/archive/2009/03/12/76354.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Thu, 12 Mar 2009 09:55:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/03/12/76354.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/76354.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/03/12/76354.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/76354.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/76354.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 梦在天涯 在上篇文章里问可不可以研究下对象与对象的类型信息怎么联系起来的，就是当调用dynamic_cast的时候为什么能够正确的识别对象的类型RTTI(Run Time Type Identification)运行时类型识别是有编译器在编译器生成的特殊类型信息，包括对象继承关系，对象本身的描述，RTTI是为多态而生成的信息，所以只有具有虚函数的对象在会生成那RTTI在哪里呢？MSVC编译器在vf...&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/03/12/76354.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/76354.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-03-12 17:55 <a href="http://www.cppblog.com/dawnbreak/archive/2009/03/12/76354.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MSVC++ 对象内存模型深入解析与具体应用 (二)</title><link>http://www.cppblog.com/dawnbreak/archive/2009/03/11/76195.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Wed, 11 Mar 2009 06:25:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/03/11/76195.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/76195.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/03/11/76195.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/76195.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/76195.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MSVC++ 对象内存模型深入解析与具体应用前言：本文之所以强调MSVC, 旨在提醒读者在不同平台和解释器下内存布局和实现上存在差异，但编程思想通用，文中内容大多来自笔者实际工作经验和网上搜集，力求正确，但水平有限，如有不当之处，敬请指出面向对象：本文面向有一定C/C++基础，并且可以读懂部分汇编的读者版权：欢迎转载，但请注明出处http://www.cppblog.com/dawnbreak...&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/03/11/76195.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/76195.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-03-11 14:25 <a href="http://www.cppblog.com/dawnbreak/archive/2009/03/11/76195.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++的静态联编和动态联编技术 </title><link>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76160.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Tue, 10 Mar 2009 15:02:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76160.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/76160.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76160.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/76160.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/76160.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要:  联编是指一个计算机程序自身彼此关联的过程。按照联编所进行的阶段不同，可分为两种不同的联编方法：静态联编和动态联编。 <br><br>静态联编 <br><br>静态联编是指联编工作出现在编译连接阶段，这种联编又称早期联编，因为这种联编过程是在程序开始运行之前完成的。 <br><br>在编译时所进行的这种联编又称静态束定。在编译时就解决了程序中的操作调用与执行该操作代码间的关系，确定这种关系又称为束定，在编译时束定又称静态束定。下面举一个静态联编的例子。&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/03/10/76160.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/76160.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-03-10 23:02 <a href="http://www.cppblog.com/dawnbreak/archive/2009/03/10/76160.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MSVC++ 对象内存模型深入解析与具体应用(一)</title><link>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76099.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Tue, 10 Mar 2009 04:57:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76099.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/76099.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76099.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/76099.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/76099.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MSVC++ 对象内存模型深入解析与具体应用前言：本文之所以强调MSVC, 旨在提醒读者在不同平台和解释器下内存布局和实现上存在差异，但编程思想通用，文中内容大多来自笔者实际工作经验和网上搜集，力求正确，但水平有限，如有不当之处，敬请指出面向对象：本文面向有一定C/C++基础，并且可以读懂部分汇编的读者版权：欢迎转载，但请注明出处http://www.cppblog.com/dawnbreak...&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/03/10/76099.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/76099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-03-10 12:57 <a href="http://www.cppblog.com/dawnbreak/archive/2009/03/10/76099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>预定义符号常量</title><link>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76089.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Tue, 10 Mar 2009 02:55:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76089.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/76089.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76089.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/76089.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/76089.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: C++继承了ANSI C的预定义常量，预处理器在处理代码时将它们替换为确定的字面常量。这些符号不能用#define重新定义，也不能用#undef取消该宏。<br><br>__LINE__ 引用语句的代码行号<br>__FILE__ 引用语句所在的文件名<br>__DATE__ 引用语句所在源文件被编译的时期<br>__TIME__ 引用语句所在源文件被编译的时间&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/03/10/76089.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/76089.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-03-10 10:55 <a href="http://www.cppblog.com/dawnbreak/archive/2009/03/10/76089.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>详解virtual table</title><link>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76084.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Tue, 10 Mar 2009 01:34:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76084.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/76084.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2009/03/10/76084.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/76084.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/76084.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: C++中的虚函数的作用主要是实现了多态的机制。关于多态，简而言之就是用父类型别的指针指向其子类的实例，然后通过父类的指针调用实际子类的成员函数。这种技术可以让父类的指针有“多种形态”，这是一种泛型技术。所谓泛型技术，说白了就是试图使用不变的代码来实现可变的算法。比如：模板技术，RTTI技术，虚函数技术，要么是试图做到在编译时决议，要么试图做到运行时决议。 <br><br>&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2009/03/10/76084.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/76084.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2009-03-10 09:34 <a href="http://www.cppblog.com/dawnbreak/archive/2009/03/10/76084.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于编译和链接</title><link>http://www.cppblog.com/dawnbreak/archive/2008/12/23/70198.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Tue, 23 Dec 2008 15:22:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2008/12/23/70198.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/70198.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2008/12/23/70198.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/70198.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/70198.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2008/12/23/70198.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/70198.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2008-12-23 23:22 <a href="http://www.cppblog.com/dawnbreak/archive/2008/12/23/70198.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WTL---WxWidget---MFC 何去何从</title><link>http://www.cppblog.com/dawnbreak/archive/2008/12/21/70016.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Sun, 21 Dec 2008 14:13:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2008/12/21/70016.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/70016.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2008/12/21/70016.html#Feedback</comments><slash:comments>22</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/70016.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/70016.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2008/12/21/70016.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/70016.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2008-12-21 22:13 <a href="http://www.cppblog.com/dawnbreak/archive/2008/12/21/70016.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用线程局部存储TLS </title><link>http://www.cppblog.com/dawnbreak/archive/2008/12/10/69107.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Wed, 10 Dec 2008 13:25:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2008/12/10/69107.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/69107.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2008/12/10/69107.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/69107.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/69107.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Thread local storage (TLS)统一进程的多个线程可以通过由TlsAlloc方法返回的索引值在线程自身的空间内存储和取回一个值。在以下这个例子里，索引值在进程开始时创建，当各个线程启动时，会各自申请一块动态内存并且将内存指针通过TlsSetValue方法存储到各自的TLS空间中（由先前的索引值标定）。CommonFunc方法使用TlsGetValue方法通过索引取得数据指针。在各个线程结束前，释放动态内存块。在进程结束见，调用TlsFree方法释放索引。&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2008/12/10/69107.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/69107.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2008-12-10 21:25 <a href="http://www.cppblog.com/dawnbreak/archive/2008/12/10/69107.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>再谈拷贝构造函数（Copy Constructor Function）</title><link>http://www.cppblog.com/dawnbreak/archive/2008/12/05/68697.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Fri, 05 Dec 2008 15:19:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2008/12/05/68697.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/68697.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2008/12/05/68697.html#Feedback</comments><slash:comments>12</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/68697.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/68697.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 前段时间有人发表了关于拷贝构造函数的问题，我觉得对于拷贝构造函数要掌握四点（以下以CCF代称拷贝构造函数）<br>第一：默认CCF提供对象之间的位拷贝（Bitwise Copy），对于指针类成员只会将至指针值复制<br>第二：CCF在对象初始化时才发挥作用，而在对象赋值的时候不起作用<br>第三：在没有显示声明成员CCF的情况下，编译器会自动生成默认CCF，如果显示声明了显示CCF，则编译器不会生成默认CCF，至少是不会调用<br>第四：与构造函数不同，CCF并不会递归的调用基类的CCF，子类与基类的CCF是覆盖关系，与就是说子类会寻找与自己关系最近的CCF调用，如果子类有CCF则仅调用子类CCF，如果子类没有向上寻找，调用第一个找到的CCF<br>第五：CCF的声明及定义如下：<br><br><br> 1classname(classname const&obj)<br> 2{<br> 3   m1=obj.m1;<br> 4   m2=obj.m2;<br> 5   .<br> 6   Lp1=new type[size];<br> 7   memcpy&nbsp;&nbsp;<a href='http://www.cppblog.com/dawnbreak/archive/2008/12/05/68697.html'>阅读全文</a><img src ="http://www.cppblog.com/dawnbreak/aggbug/68697.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2008-12-05 23:19 <a href="http://www.cppblog.com/dawnbreak/archive/2008/12/05/68697.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对于c++中常量成员函数，返回常量引用，const_cast的总结</title><link>http://www.cppblog.com/dawnbreak/archive/2008/12/04/68571.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Thu, 04 Dec 2008 09:08:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2008/12/04/68571.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/68571.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2008/12/04/68571.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/68571.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/68571.html</trackback:ping><description><![CDATA[<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 18pt; BACKGROUND: red; COLOR: white; FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-themecolor: background1; mso-highlight: red">常量成员函数：</span><span lang=EN-US style="FONT-SIZE: 18pt; COLOR: white; mso-themecolor: background1"><o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">先看这个例子<span lang=EN-US><o:p></o:p></span></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">bool Sales_item::same_isbn(</span><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #0070c0; FONT-FAMILY: 黑体">const</span><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128"> Sales_item &amp;rhs) </span><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: red; FONT-FAMILY: 黑体">const</span><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128"><o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">{ return (isbn rhs.isbn);}<o:p></o:p></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">蓝色的<span lang=EN-US>const</span>用于修饰显示传入的形参<span lang=EN-US>rhs</span>，而对于类的成员则有隐式的，而外的<span lang=EN-US>this</span>指针作为形参传入，而红色部分的<span lang=EN-US>const</span>正是修饰这部分参数<span lang=EN-US>this</span>；<span lang=EN-US><o:p></o:p></span></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">const </span><span style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">成员函数的引入<span lang=EN-US><o:p></o:p></span></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">现在，可以理解跟在<span lang=EN-US>Sales_item </span>成员函数声明的形参表后面的<span lang=EN-US>const </span>所起的作用了<span lang=EN-US>: const</span>改变了隐含的<span lang=EN-US>this </span>形参的类型。在调用<span lang=EN-US>total.same_isbn(trans) </span>时，隐含的<span lang=EN-US>this </span>形参将是一个指向<span lang=EN-US>total </span>对象的<span lang=EN-US>const Sales_i</span><span lang=EN-US>tem*</span>类型的指针。就像如下编写<span lang=EN-US>same_isbn </span>的函数体一样<span lang=EN-US>:<o:p></o:p></span></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128"><o:p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;pseudo</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">code&nbsp;illustration&nbsp;of&nbsp;how&nbsp;the&nbsp;</span><span style="COLOR: #0000ff">implicit</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">&nbsp;pointer&nbsp;</span><span style="COLOR: #0000ff">is</span><span style="COLOR: #000000">&nbsp;used<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;This&nbsp;code&nbsp;</span><span style="COLOR: #0000ff">is</span><span style="COLOR: #000000">&nbsp;illegal:&nbsp;We&nbsp;may&nbsp;not&nbsp;explicitly&nbsp;define&nbsp;the&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">&nbsp;pointer&nbsp;ourselves<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">&nbsp;Note&nbsp;that&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">is</span><span style="COLOR: #000000">&nbsp;a&nbsp;pointer&nbsp;to&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;because&nbsp;same_isbn&nbsp;</span><span style="COLOR: #0000ff">is</span><span style="COLOR: #000000">&nbsp;a&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;member<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">&nbsp;Sales_item::same_isbn(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;Sales&nbsp;item&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">&nbsp;,</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;Sales_item&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">rhs)&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img id=Codehighlighter1_319_350_Open_Image onclick="this.style.display='none'; Codehighlighter1_319_350_Open_Text.style.display='none'; Codehighlighter1_319_350_Closed_Image.style.display='inline'; Codehighlighter1_319_350_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_319_350_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_319_350_Closed_Text.style.display='none'; Codehighlighter1_319_350_Open_Image.style.display='inline'; Codehighlighter1_319_350_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_319_350_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_319_350_Open_Text><span style="COLOR: #000000">{&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">isbn&nbsp;rhs.isbn);}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"></o:p></span>&nbsp;</p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">用这种方式使用<span lang=EN-US>const </span>的函数称为常量成员函数<span lang=EN-US>(const member function) </span>。由于<span lang=EN-US>this </span>是指向<span lang=EN-US>const </span>对象的指针，<span lang=EN-US>const </span>成员函数不能修改调用该函数的对象。因此，函数<span lang=EN-US>avg-price<o:p></o:p></span></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">和函数<span lang=EN-US>sarne isbn </span>只能读取而不能修改调用它们的对象的数据成员。<span lang=EN-US><o:p></o:p></span></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">NOTE</span><span style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">：<span lang=EN-US><o:p></o:p></span></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">const</span><span style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128">对象指向<span lang=EN-US>const</span>的指针或引用只能用于调用其<span lang=EN-US>const</span>成员函数如果尝试用它们来调用非<span lang=EN-US>const </span>成员函数，则是错误的。<span lang=EN-US><o:p></o:p></span></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span lang=EN-US style="FONT-SIZE: 14pt; COLOR: #632423; FONT-FAMILY: 黑体; mso-themecolor: accent2; mso-themeshade: 128"><o:p>&nbsp;</o:p></span></p>
<p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><span style="FONT-SIZE: 18pt; BACKGROUND: red; COLOR: white; FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-themecolor: background1; mso-highlight: red">返回常量引用</span><span lang=EN-US style="FONT-SIZE: 18pt; BACKGROUND: red; COLOR: white; mso-themecolor: background1; mso-highlight: red"><font face=Calibri>:<o:p></o:p></font></span></p>
<p dir=ltr>&nbsp;</p>
<h1><span>在看一个例子：</span></h1>
<span>
<h1 align=left>
<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: #000000">mycls&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">&nbsp;returntest()</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">定义返回值为一个常量引用</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #008000"><img id=Codehighlighter1_40_127_Open_Image onclick="this.style.display='none'; Codehighlighter1_40_127_Open_Text.style.display='none'; Codehighlighter1_40_127_Closed_Image.style.display='inline'; Codehighlighter1_40_127_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_40_127_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_40_127_Closed_Text.style.display='none'; Codehighlighter1_40_127_Open_Image.style.display='inline'; Codehighlighter1_40_127_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_40_127_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_40_127_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mycls&nbsp;my1(</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">a&nbsp;in&nbsp;the&nbsp;func&nbsp;is</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;&amp;</span><span style="COLOR: #000000">my1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;my1;<br></span><span style="COLOR: #008080">&nbsp;6</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">&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;_tmain(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;argc,&nbsp;_TCHAR</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;argv[])<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img id=Codehighlighter1_166_462_Open_Image onclick="this.style.display='none'; Codehighlighter1_166_462_Open_Text.style.display='none'; Codehighlighter1_166_462_Closed_Image.style.display='inline'; Codehighlighter1_166_462_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_166_462_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_166_462_Closed_Text.style.display='none'; Codehighlighter1_166_462_Open_Image.style.display='inline'; Codehighlighter1_166_462_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_166_462_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_462_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">测试返回引用类型</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">10</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mycls&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">str&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;returntest();</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">使用cont&amp;接受返回值<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">str.m_q=12;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">编译报错，不可以修改const类型</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">12</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mycls&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">str1</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">const_cast</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">mycls</span><span style="COLOR: #000000">&amp;&gt;</span><span style="COLOR: #000000">(str);</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">去掉const属性，以便修改</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">13</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str1.m_q</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&amp;b=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;&amp;</span><span style="COLOR: #000000">str</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&amp;b=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;&amp;</span><span style="COLOR: #000000">str1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</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/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div>
</h1>
<p align=left>以上mycls是我自己定义的一个类，声明如下<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">&nbsp;1</span><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;mycls<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img id=Codehighlighter1_12_348_Open_Image onclick="this.style.display='none'; Codehighlighter1_12_348_Open_Text.style.display='none'; Codehighlighter1_12_348_Closed_Image.style.display='inline'; Codehighlighter1_12_348_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_12_348_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_12_348_Closed_Text.style.display='none'; Codehighlighter1_12_348_Open_Image.style.display='inline'; Codehighlighter1_12_348_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_12_348_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_12_348_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mycls(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a);<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;a[</span><span style="COLOR: #000000">100000</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">~mycls(void);</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #008000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;m_q;<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;template&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">&nbsp;T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;inline&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;compare(</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;T&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">a,</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">&nbsp;T&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">b)<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img id=Codehighlighter1_149_249_Open_Image onclick="this.style.display='none'; Codehighlighter1_149_249_Open_Text.style.display='none'; Codehighlighter1_149_249_Closed_Image.style.display='inline'; Codehighlighter1_149_249_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_149_249_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_149_249_Closed_Text.style.display='none'; Codehighlighter1_149_249_Open_Image.style.display='inline'; Codehighlighter1_149_249_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_149_249_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_149_249_Open_Text><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;b)<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;b)<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">b)<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</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/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</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/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></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/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;mycls</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">operator</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">(mycls&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dosomething(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;a);<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">virtual</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;doanotherthing(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">21</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">22</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
通过代码注释，我想这不难理解，用一个引用类型的返回值最大好处就是可以避免内存拷贝，注意到我的类中有一个长度为100000的char数组，我想频繁拷贝这个数组对于一下性能较低的机器还是很耗时的，这时我们返回const &amp;类型，避免了文件的拷贝，从输出也可以看到，returntest函数内的对象地址与main函数内所返回的引用对象地址完全一致。</span>
<h1 align=left><br>&nbsp;</h1>
<img src ="http://www.cppblog.com/dawnbreak/aggbug/68571.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2008-12-04 17:08 <a href="http://www.cppblog.com/dawnbreak/archive/2008/12/04/68571.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>STL写的字符替换程序</title><link>http://www.cppblog.com/dawnbreak/archive/2008/12/03/68478.html</link><dc:creator>pear_li</dc:creator><author>pear_li</author><pubDate>Wed, 03 Dec 2008 09:27:00 GMT</pubDate><guid>http://www.cppblog.com/dawnbreak/archive/2008/12/03/68478.html</guid><wfw:comment>http://www.cppblog.com/dawnbreak/comments/68478.html</wfw:comment><comments>http://www.cppblog.com/dawnbreak/archive/2008/12/03/68478.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/dawnbreak/comments/commentRss/68478.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/dawnbreak/services/trackbacks/68478.html</trackback:ping><description><![CDATA[最近看关联容器相关章节，写了以下程序，作用是先从传入参数的第一个文件中读入键值对，key是目标字串，mapped是要替换的字串，然其后传入文件里的相关字串<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: #000000">#include&nbsp;</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">&nbsp;2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">sstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><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>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">fstream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><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>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><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>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">stdexcept</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><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">using</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">&nbsp;std;<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></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"><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>main(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;args,</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">&nbsp;argv[])<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img id=Codehighlighter1_165_956_Open_Image onclick="this.style.display='none'; Codehighlighter1_165_956_Open_Text.style.display='none'; Codehighlighter1_165_956_Closed_Image.style.display='inline'; Codehighlighter1_165_956_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_165_956_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_165_956_Closed_Text.style.display='none'; Codehighlighter1_165_956_Open_Image.style.display='inline'; Codehighlighter1_165_956_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_165_956_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_165_956_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img id=Codehighlighter1_173_829_Open_Image onclick="this.style.display='none'; Codehighlighter1_173_829_Open_Text.style.display='none'; Codehighlighter1_173_829_Closed_Image.style.display='inline'; Codehighlighter1_173_829_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_173_829_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_173_829_Closed_Text.style.display='none'; Codehighlighter1_173_829_Open_Image.style.display='inline'; Codehighlighter1_173_829_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_173_829_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_173_829_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(args</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000">&nbsp;runtime_error(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">缺少参数，请输入。。。</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;ifstream&nbsp;fin;<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;fin.open(argv[</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/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">fin) //检查文件是否被正确打开<br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000">&nbsp;runtime_error(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">map&nbsp;file&nbsp;not&nbsp;found</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/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;keystr,mapstr;<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;mappedctner;<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">keystr</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">mapstr)<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img id=Codehighlighter1_400_433_Open_Image onclick="this.style.display='none'; Codehighlighter1_400_433_Open_Text.style.display='none'; Codehighlighter1_400_433_Closed_Image.style.display='inline'; Codehighlighter1_400_433_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_400_433_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_400_433_Closed_Text.style.display='none'; Codehighlighter1_400_433_Open_Image.style.display='inline'; Codehighlighter1_400_433_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_400_433_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_400_433_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mappedctner[keystr]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">mapstr;//采用下标引用的方法插入元素<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><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>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cnt(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">);cnt</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">args;cnt</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img id=Codehighlighter1_469_826_Open_Image onclick="this.style.display='none'; Codehighlighter1_469_826_Open_Text.style.display='none'; Codehighlighter1_469_826_Closed_Image.style.display='inline'; Codehighlighter1_469_826_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_469_826_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_469_826_Closed_Text.style.display='none'; Codehighlighter1_469_826_Open_Image.style.display='inline'; Codehighlighter1_469_826_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_469_826_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_469_826_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.close();<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.clear();<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.open(argv[cnt]);<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stringstream&nbsp;sstr;<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sstr</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">target&nbsp;file&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">cnt</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;not&nbsp;found</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;//格式化字串<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">fin)<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000">&nbsp;runtime_error(sstr.str());//str()成员存储输入的文本对象<br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">::iterator&nbsp;itr;<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(fin</span><span style="COLOR: #000000">&gt;&gt;</span><span style="COLOR: #000000">keystr)<br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img id=Codehighlighter1_702_809_Open_Image onclick="this.style.display='none'; Codehighlighter1_702_809_Open_Text.style.display='none'; Codehighlighter1_702_809_Closed_Image.style.display='inline'; Codehighlighter1_702_809_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_702_809_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_702_809_Closed_Text.style.display='none'; Codehighlighter1_702_809_Open_Image.style.display='inline'; Codehighlighter1_702_809_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_702_809_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_702_809_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">((itr</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">mappedctner.find(keystr))</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">mappedctner.end())<br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;keystr</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">itr</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">second;//找到相关字串，利用迭代器引用second的mappedvalue类型替换<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">keystr</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></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/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000">(runtime_error&nbsp;e)<br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img id=Codehighlighter1_856_883_Open_Image onclick="this.style.display='none'; Codehighlighter1_856_883_Open_Text.style.display='none'; Codehighlighter1_856_883_Closed_Image.style.display='inline'; Codehighlighter1_856_883_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_856_883_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_856_883_Closed_Text.style.display='none'; Codehighlighter1_856_883_Open_Image.style.display='inline'; Codehighlighter1_856_883_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_856_883_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_856_883_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">e.what()</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">47</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000">(ios_base::failure&nbsp;e)<br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img id=Codehighlighter1_914_943_Open_Image onclick="this.style.display='none'; Codehighlighter1_914_943_Open_Text.style.display='none'; Codehighlighter1_914_943_Closed_Image.style.display='inline'; Codehighlighter1_914_943_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_914_943_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_914_943_Closed_Text.style.display='none'; Codehighlighter1_914_943_Open_Image.style.display='inline'; Codehighlighter1_914_943_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_914_943_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_914_943_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">50</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">e.what()</span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000">endl;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">53</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">54</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<br>
<img src ="http://www.cppblog.com/dawnbreak/aggbug/68478.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/dawnbreak/" target="_blank">pear_li</a> 2008-12-03 17:27 <a href="http://www.cppblog.com/dawnbreak/archive/2008/12/03/68478.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>