﻿<?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++ Glean</title><link>http://www.cppblog.com/netnchen/</link><description>C++ is a Culture</description><language>zh-cn</language><lastBuildDate>Wed, 08 Apr 2026 16:20:10 GMT</lastBuildDate><pubDate>Wed, 08 Apr 2026 16:20:10 GMT</pubDate><ttl>60</ttl><item><title>无题</title><link>http://www.cppblog.com/netnchen/archive/2009/05/25/85728.html</link><dc:creator>Neal</dc:creator><author>Neal</author><pubDate>Mon, 25 May 2009 09:17:00 GMT</pubDate><guid>http://www.cppblog.com/netnchen/archive/2009/05/25/85728.html</guid><wfw:comment>http://www.cppblog.com/netnchen/comments/85728.html</wfw:comment><comments>http://www.cppblog.com/netnchen/archive/2009/05/25/85728.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/netnchen/comments/commentRss/85728.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/netnchen/services/trackbacks/85728.html</trackback:ping><description><![CDATA[很久没有来过了，都忘了自己曾经雄心勃勃的在这儿开了个博客~ 虽然天天在用C++，却越发觉得自己的浅薄了；呵呵，年纪一大把了，也不知何时才能静下心来真正的做点事情。<br><br>推荐两个相关的RSS吧<br>http://www.ddj.com/rss/cpp.xml<br>http://www.ddj.com/rss/architect.xml<br><br>自己也要多看看，才能不断的进步啊~<br><br><img src ="http://www.cppblog.com/netnchen/aggbug/85728.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/netnchen/" target="_blank">Neal</a> 2009-05-25 17:17 <a href="http://www.cppblog.com/netnchen/archive/2009/05/25/85728.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC8 的 hash_map</title><link>http://www.cppblog.com/netnchen/archive/2007/04/03/21166.html</link><dc:creator>Neal</dc:creator><author>Neal</author><pubDate>Tue, 03 Apr 2007 06:01:00 GMT</pubDate><guid>http://www.cppblog.com/netnchen/archive/2007/04/03/21166.html</guid><wfw:comment>http://www.cppblog.com/netnchen/comments/21166.html</wfw:comment><comments>http://www.cppblog.com/netnchen/archive/2007/04/03/21166.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/netnchen/comments/commentRss/21166.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/netnchen/services/trackbacks/21166.html</trackback:ping><description><![CDATA[刚刚装上VC8，发现VC8现在也支持hash_map了，终于可以不用STLPort了（不是不想用，而是在VC里面用太TNND麻烦了）。不过VC8上的hash-map还是有不爽的地方 1。它定义在stdext namespace 中 2。它需要至少specialize两个template来添加自定义类。。。不过终究还是算不小的的进步啦;D =====================================<br><br><br>============ VC2005 ================<br>// test.cpp : Defines the entry point for the console application.<br>//<br><br>#include "stdafx.h"<br>#include <string><br>#include <iostream><br>#include <hash_map><br><br>struct Key{<br>&nbsp; int i;<br>};<br><br><font color=red><br>namespace std {<br>&nbsp; template &lt;&gt; struct less&lt;::Key&gt;<br>&nbsp;&nbsp; : public binary_function&lt;::Key, ::Key, bool&gt;<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; bool operator()(const ::Key&amp; _Left, const ::Key&amp; _Right) const<br>&nbsp;&nbsp;&nbsp; { // apply operator&lt; to operands<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (_Left.i &lt; _Right.i);<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; };<br>}<br><br>namespace <strong>stdext </strong>{<br>&nbsp; template &lt;&gt; size_t hash_value<key>(const Key &amp;key){<br>&nbsp;&nbsp;&nbsp; return hash_value<int>(key.i);<br>&nbsp; }<br>}<br></font><br>int _tmain(int argc, _TCHAR* argv[])<br>{<br>&nbsp; stdext::hash_map<key, std::string> testmap;&nbsp; <br>&nbsp; Key k;<br>&nbsp; k.i = 1;<br>&nbsp; testmap[k] = std::string("hello, world");<br>&nbsp; testmap[k] = std::string("hello, again");<br><br>&nbsp; std::cout &lt;&lt; "size of map: " &lt;&lt; testmap.size() &lt;&lt; std::endl;<br>&nbsp; return 0;<br>}<br><br>============GCC + STLPort ===========<br>struct Key {<br>&nbsp; ...<br>};<br><br><font color=red><br>namespace std {<br>&nbsp; template &lt;&gt; struct hash<key> {<br>&nbsp;&nbsp;&nbsp; size_t operator()(const Key &amp;key) const {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br>&nbsp;&nbsp;&nbsp; };<br>&nbsp; }<br>}<br></font><br><br>int main()<br>{<br>&nbsp; ...<br>}<br><br>
<img src ="http://www.cppblog.com/netnchen/aggbug/21166.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/netnchen/" target="_blank">Neal</a> 2007-04-03 14:01 <a href="http://www.cppblog.com/netnchen/archive/2007/04/03/21166.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>做个广告...</title><link>http://www.cppblog.com/netnchen/archive/2007/03/28/20777.html</link><dc:creator>Neal</dc:creator><author>Neal</author><pubDate>Wed, 28 Mar 2007 08:43:00 GMT</pubDate><guid>http://www.cppblog.com/netnchen/archive/2007/03/28/20777.html</guid><wfw:comment>http://www.cppblog.com/netnchen/comments/20777.html</wfw:comment><comments>http://www.cppblog.com/netnchen/archive/2007/03/28/20777.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/netnchen/comments/commentRss/20777.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/netnchen/services/trackbacks/20777.html</trackback:ping><description><![CDATA[呵呵，欢迎大家访问偶的网站哈<br /><a href="http://travian.infinites.net">http://travian.infinites.net</a><br /><br />
做的很丑陋，不过偶不善于HTML嘛
<br />
嘿嘿<img src ="http://www.cppblog.com/netnchen/aggbug/20777.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/netnchen/" target="_blank">Neal</a> 2007-03-28 16:43 <a href="http://www.cppblog.com/netnchen/archive/2007/03/28/20777.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++的编程模型</title><link>http://www.cppblog.com/netnchen/archive/2007/03/28/20764.html</link><dc:creator>Neal</dc:creator><author>Neal</author><pubDate>Wed, 28 Mar 2007 06:29:00 GMT</pubDate><guid>http://www.cppblog.com/netnchen/archive/2007/03/28/20764.html</guid><wfw:comment>http://www.cppblog.com/netnchen/comments/20764.html</wfw:comment><comments>http://www.cppblog.com/netnchen/archive/2007/03/28/20764.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/netnchen/comments/commentRss/20764.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/netnchen/services/trackbacks/20764.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一种语言代表了一种思维，而思维决定了问题的解决方式。</span>
				<span lang="ZH-CN">
				</span>
				<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
				<o:p>
				</o:p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<o:p> </o:p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从程序设计语言出现到现在已经经历了四代。大多数高级语言都对应到第三代或四代程序设计语言。按其主要支持的编程模型（思维模式）分类，大致可以分为如下类型</span>
				<span lang="ZH-CN">
				</span>
				<o:p>
				</o:p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; tab-stops: list 36.0pt">
				<span style="mso-fareast-font-family: 'Times New Roman'">1</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">．</span>
				<span lang="ZH-CN" style="mso-fareast-font-family: 'Times New Roman'">
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">过程型：这类语言把应用抽象为序列化的操作步骤，其典型代表如</span>PASCAL<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span>C<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">等。</span><o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; tab-stops: list 36.0pt">
				<span style="mso-fareast-font-family: 'Times New Roman'">2</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">．</span>
				<span lang="ZH-CN" style="mso-fareast-font-family: 'Times New Roman'">
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数型：这类语言把应用抽象为函数（按定义，函数是从一个域到另一个域的映射）；它们试图把问题分解为集合和集合间的函数关系。典型代表是</span>LISP<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; tab-stops: list 36.0pt">
				<span style="mso-fareast-font-family: 'Times New Roman'">3</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">．</span>
				<span lang="ZH-CN" style="mso-fareast-font-family: 'Times New Roman'">
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">逻辑型：这类语言把问题抽象为事实与规则的结合，试图通过逻辑演算解决实际问题。典型代表是</span>PROLOG<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; tab-stops: list 36.0pt">
				<span style="mso-fareast-font-family: 'Times New Roman'">4</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">．</span>
				<span lang="ZH-CN" style="mso-fareast-font-family: 'Times New Roman'">
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">面向对象型：这类语言从上世纪</span>80<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">年代后迅速发展，这类语言试图将实际问题抽象为独立的对象以及对象间的交互，典型代表是早期的</span>SmallTalk<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</span>Eiffel<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; tab-stops: list 36.0pt">
				<span style="mso-fareast-font-family: 'Times New Roman'">5</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">．</span>
				<span lang="ZH-CN" style="mso-fareast-font-family: 'Times New Roman'">
				</span>
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">面向数据结构型：这类语言将问题抽象为对结构化数据的操作，例如现在常用的</span>SQL<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<o:p> </o:p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">作为一个诞生与上世纪</span>80<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">年代初期的编程语言，</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">被广泛的认为是一种支持面向对象的语言；但是，我认为</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的伟大之处却更多的在于（除了所提供完备的面向对象支持）它同样提供了</span>C<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的面向过程的编程模型以及只有少数高级语言能支持的范型编程（我更喜欢叫它面向算法的编程）。在实际的应用过程中，我们往往需要不同层次的抽象，</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所支持的广泛的编程模型为我们提供了强大和灵活的工具，使得我们在设计和实现时能自如的选择不同的模型，以最合理的（组合）方式解决问题。</span><o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<o:p> </o:p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不可否认，在当今的程序设计中，面向对象已经基本上是一统江湖，但它往往并不是最合理的选择；例如在针对协议栈的开发中，使用面向过程的模型往往优于使用面向对象的模型（或许这也是为什么主流的电信设备供应商坚持使用</span>C<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的原因？）；而在针对算法进行抽象时，使用面向对象的思维模式几乎完全是不可行的（算法和对象间的不同之处是显而易见的）；如果机械的运用面向对象思维，只能使最终产品的质量、可维护性、可读性下降。</span><o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<o:p> </o:p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或许有人会问，那么应该如何选择抽象方式呢？我觉得这个应该是因人和问题的不同而不同的，关键是在使用</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的过程中，多从这些方面进行思考、总结，以体会采用不同模式解决问题的优缺点，努力使用最合理的方式（或组合）对问题进行抽象并加以解决。我也常常为这些种种选择而迷惑，因此在这儿也希望那些已经到了“不惑”层次的哥们多多指教。</span><o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<o:p> </o:p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当然，从另一方面来说，越多的选择往往意味着越难的选择，这或许也是为什么现在这么多人趋骛与更单纯、更简单的</span>JAVA<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</span>C#<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的原因吧；但是当我们真正理解并掌握</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">提供的这些编程模型时，我想我们会更加坚定当初选择</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的信念</span>;D<o:p></o:p></p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<o:p> </o:p>
		</p>
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span lang="ZH-CN" style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">时间仓促，不正之处敬请指教。</span>
				<span lang="ZH-CN" style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">
				</span>
		</p>
<img src ="http://www.cppblog.com/netnchen/aggbug/20764.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/netnchen/" target="_blank">Neal</a> 2007-03-28 14:29 <a href="http://www.cppblog.com/netnchen/archive/2007/03/28/20764.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我看C++中的Object, Class &amp; Instance</title><link>http://www.cppblog.com/netnchen/archive/2007/03/22/20339.html</link><dc:creator>Neal</dc:creator><author>Neal</author><pubDate>Thu, 22 Mar 2007 02:34:00 GMT</pubDate><guid>http://www.cppblog.com/netnchen/archive/2007/03/22/20339.html</guid><wfw:comment>http://www.cppblog.com/netnchen/comments/20339.html</wfw:comment><comments>http://www.cppblog.com/netnchen/archive/2007/03/22/20339.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cppblog.com/netnchen/comments/commentRss/20339.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/netnchen/services/trackbacks/20339.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt">C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，经常用到对象（</span>Object<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）、类（</span>Class<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）和实例（</span>Instance<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）等概念，一直对这几个概念有些混淆，今天算是整理一下自己的思路，谈谈自己对这几个概念的看法吧；希望不当之处大家能够指出，也欢迎大家看看自己的看法。<br /></span><br /><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从其定义来看，对象是指一个能完成特定操作，具有特定属性的实体（</span>Component<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）；类是具有相同属性对象的集合（</span>Group of Objects<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）。实例则往往被理解为一个对象的具体化。<br /><br /></span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象更多的是一个概念，在象</span>SmallTalk<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这类纯粹的</span>OO<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语言中，所有东西都是对象（</span>MetaClass, Class, Instances<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）；而类在不过是一个特殊的、能作为模板创建实例的对象。（一直想弄个</span>SmallTalk<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来玩玩，但终究没有时间和精力去学习。）<br /><br /></span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，“对象”概念往往被模糊化，它不是一个能包括一切的概念，而在某些环境下成为能和类与实例相互替换的概念。<br /><br /></span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">原因之一，或许是在</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对类的定义。</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">把类定义为一个抽象数据类型（</span>ADT<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）。而</span>ADT<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">只是一个实现上的概念，它在运行时并不存在一个对象所应该具有的特征（属性和行为）。虽然</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中引入了运行时类型信息（</span>RTTI<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，参看</span>type_info<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类），但仍然很难把类当成一个对象。从这个角度来说，在实现时类可以看作是对象概念的代名词。<br /><br /></span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">原因之二，个人觉得应该是和使用这些概念的上下文有关。在使用</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">时（包括设计模式），往往需要考虑两个层次的抽象：<br /></span>1. <span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">编码（实现）时的抽象</span><br />2. <span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">运行时的抽象<br /><br /></span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在实现时，</span>C++<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，无疑类的概念和对象的概念是一致的，而实例则可以理解为一个类的实例化或一个对象的具体化；对应与</span>Design Pattern<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，那些结构化的模式（</span>Structural Patterns<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）更适合与这一层次的抽象。<br /><br /></span><span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在运行时，个人觉得对象更多的是和实例等同的。我们说某个对象和另外一个对象交互更多的是在表达某个类的一个实例和另一个类的一个实例进行交互，这个时候，对象不再是一个概念，而是被具体化了。而设计模式中的行为模式（</span>Behavioral Patterns<span lang="ZH-CN" style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）则更适合与这个层次的抽象。<br /><br />以上是我对这几个基本概念的理解，请大家批评指教！<br />//bow</span></p>
<img src ="http://www.cppblog.com/netnchen/aggbug/20339.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/netnchen/" target="_blank">Neal</a> 2007-03-22 10:34 <a href="http://www.cppblog.com/netnchen/archive/2007/03/22/20339.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hello, World</title><link>http://www.cppblog.com/netnchen/archive/2007/03/20/20219.html</link><dc:creator>Neal</dc:creator><author>Neal</author><pubDate>Tue, 20 Mar 2007 08:02:00 GMT</pubDate><guid>http://www.cppblog.com/netnchen/archive/2007/03/20/20219.html</guid><wfw:comment>http://www.cppblog.com/netnchen/comments/20219.html</wfw:comment><comments>http://www.cppblog.com/netnchen/archive/2007/03/20/20219.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/netnchen/comments/commentRss/20219.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/netnchen/services/trackbacks/20219.html</trackback:ping><description><![CDATA[
		<p>"C++ is a Culture"</p>
		<p>这是我的第一篇文章，就用标准的C++思维开始吧。<br /><br />"Hello, World"是我写的第一个程序，它也是我第一篇文章的标题。以前很少写东西，原因之一是发现自己总是无法表达自己。最近越来越发现能表达自己的重要性了，万事开头难，何不就从C++开始呢？就象十年前刚刚接触C++时从一个"Hello, World"开始一样。<br /><br />C++的迷人之处在于它能让我自由的表达自己的思想，能自由的控制自己的一切……它对我，或者对广大C++爱好者而言，已经不仅仅是编程语言了，它是一种文化！文化是会发展的，所以我不会感到厌倦；文化是博大的，所以我感到自己的渺小；文化是包容的，所以我才希望自己能为它做出自己的贡献，哪怕是一点点，自己也满足了。<br /><br />今后我会慢慢写出一些我的心得，对C++，对Design Patterns以及一切我对这个文化的感悟……希望大家能喜欢，也希望大家和我一样对C++充满敬畏之情。<br /><br />向Bjarne Stroustrup致敬！</p>
<img src ="http://www.cppblog.com/netnchen/aggbug/20219.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/netnchen/" target="_blank">Neal</a> 2007-03-20 16:02 <a href="http://www.cppblog.com/netnchen/archive/2007/03/20/20219.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>