﻿<?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++博客-Seer Lee-文章分类-CS_C++Ruminations</title><link>http://www.cppblog.com/SeerLee/category/3215.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 22 May 2008 10:24:14 GMT</lastBuildDate><pubDate>Thu, 22 May 2008 10:24:14 GMT</pubDate><ttl>60</ttl><item><title>C++_对象创建_类型转换</title><link>http://www.cppblog.com/SeerLee/articles/16108.html</link><dc:creator>Seer_Lee</dc:creator><author>Seer_Lee</author><pubDate>Thu, 07 Dec 2006 14:53:00 GMT</pubDate><guid>http://www.cppblog.com/SeerLee/articles/16108.html</guid><wfw:comment>http://www.cppblog.com/SeerLee/comments/16108.html</wfw:comment><comments>http://www.cppblog.com/SeerLee/articles/16108.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/SeerLee/comments/commentRss/16108.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/SeerLee/services/trackbacks/16108.html</trackback:ping><description><![CDATA[改革 <img src ="http://www.cppblog.com/SeerLee/aggbug/16108.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/SeerLee/" target="_blank">Seer_Lee</a> 2006-12-07 22:53 <a href="http://www.cppblog.com/SeerLee/articles/16108.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++_名字查询</title><link>http://www.cppblog.com/SeerLee/articles/16066.html</link><dc:creator>Seer_Lee</dc:creator><author>Seer_Lee</author><pubDate>Wed, 06 Dec 2006 13:43:00 GMT</pubDate><guid>http://www.cppblog.com/SeerLee/articles/16066.html</guid><wfw:comment>http://www.cppblog.com/SeerLee/comments/16066.html</wfw:comment><comments>http://www.cppblog.com/SeerLee/articles/16066.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.cppblog.com/SeerLee/comments/commentRss/16066.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/SeerLee/services/trackbacks/16066.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体">
						<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体">
								<font color="#008000">
								</font>
								<br />
								<font size="4">   </font>
						</span>
				</span>
				<span style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 宋体">
						<span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 新宋体">
						</span>
						<span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 新宋体">
								<font size="4">所以，为了试图寻找匹配的函数，编译器应该到名字空间<span lang="EN-US">N</span>中去查找。</font> </span>
						<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 新宋体">
								<br />
						</span>
						<span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 新宋体">
								<font size="4">    但这段代码在<span lang="EN-US">Visual C++</span>中却失败了。</font>
								<br />
						</span>
						<span lang="EN-US" style="FONT-SIZE: 9pt; COLOR: blue; FONT-FAMILY: 新宋体">
								<br />我们的技术<font color="#000000">就很好啊，所以也不一定就好。<br /></font><br />我很 关抓 <br /><br />是这样的<br /><br /></span>
				</span>
		</p>
<img src ="http://www.cppblog.com/SeerLee/aggbug/16066.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/SeerLee/" target="_blank">Seer_Lee</a> 2006-12-06 21:43 <a href="http://www.cppblog.com/SeerLee/articles/16066.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++_操作符重载</title><link>http://www.cppblog.com/SeerLee/articles/16065.html</link><dc:creator>Seer_Lee</dc:creator><author>Seer_Lee</author><pubDate>Wed, 06 Dec 2006 13:30:00 GMT</pubDate><guid>http://www.cppblog.com/SeerLee/articles/16065.html</guid><wfw:comment>http://www.cppblog.com/SeerLee/comments/16065.html</wfw:comment><comments>http://www.cppblog.com/SeerLee/articles/16065.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/SeerLee/comments/commentRss/16065.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/SeerLee/services/trackbacks/16065.html</trackback:ping><description><![CDATA[
		<span style="font-weight: bold;">         <br /><br /><br />               C++_操作符重载_1<br /><br /></span>
		<font color="#ff0000">
				<font color="#008000">
						<br />
						<font color="#ff0000">
								<u>
										<b>1</b> </u> 
						</font>
				</font>
		</font>C++为什么要有操作符重载？<br /><br />    C++为内置的数据类型都定义了一些内置操作符。<br />    这些操作符定义了内置数据类型支持的各种操作。<br />    <br />    并且<br />    C++允许用户定义自己的用户类型（<font color="#0000ff">user-define type</font>），<br />    以及这个用户类型所支持的各种操作函数。<br /><br />    我们有时候希望<br />    我们自己定义的用户类型也支持内置类型所支持的操作，<br />    我们可以通过定义用户类成员函数来间接实现这个目的，<br /><br />    但是用户类成员函数在使用时，其语法必须符合函数调用格式，<br />    这种格式看起来和内置类型操作符相比，不够简洁，<br />    <font color="#0000ff">多个函数调用的组合不能够象内置操作符组合那样直接，干净，自然 ！</font><br /><br />    幸运的是：C++允许用户自己定义用户类支持的内置操作符，<br />    并且支持象内置类型使用内置操作符时的语法描述格式。<br />    <font color="#0000ff">使多个用户类型的函数调用组合在形式上转化为内置操作符组合形式</font><br />    <font color="#0000ff">自然，直接！</font><br /><br />    这看起来用户类和内置类之间没有了实质性区别，<br />    仿佛用户类和其支持的操作本身就属于语言的一部分，<br />    也可以对用户类型的数据和操作符的进行自由组合 ！<br /><br />    比如：<br />    操作符形式：<br />    <font color="#0000ff">std::string result = "nihao" + " ma" - "a" + "\n" ;</font><br />    函数调用形式：<br />    <font color="#0000ff">std::string result = "nihao".operator+(" ma").operator-("a").operator+("\n");<br /> <br />    </font><font color="#0000ff"><font color="#000000">C++ Ruminations 中的名言：</font></font><font color="#0000ff">用户类设计就是语言设计 ！<br /><br /></font>    <font color="#ff0000">结论：<br />    1) </font><font color="#0000ff"><font color="#ff0000">操作符重载允许我们通过用户类设计进行语言设计，<br /></font><br /></font><font color="#0000ff"><br /></font><br /><span style="font-weight: bold;"></span><font color="#ff0000"><b><u>2</u></b> </font> 编译器如何查找语句（<font color="#000000">a operator@ b</font>）中操作符@的定义呢？<br /><br />    <font color="#0000ff">Operator Look-up</font>规则定义了一个操作符名字和操作符定义之间的映射规则<span style="font-weight: bold;">。<br />   </span>根据这个规则编译器找到操作符名字的定义。<br /><br />    <font color="#ff0000"><font color="#0000ff">C++LS</font></font>中是这样描述的：<br /><br />    <font color="#0000ff">a是X类型，b是Y类型</font>；<br />    查找过程在这四步中一直进行，每执行一步结束时检查是否找到合适的定义，如果找到则停止。<br />   （可能这一步找到<font color="#0000ff">多个定义</font>）：<br /><br />    1) 如果X是一个类，则在X的成员函数中查找 <font color="#000000">operator@</font> 的定义，或者在X的基类中查找<br />    2) 在包含 <font color="#000000" size="3">a operator@ b</font> 语句的上下文<font color="#0000ff">（contex</font>）中查找<br />    3) 如果X定义在名字空间N中，则在N中的自由函数中查找<br />    4) 如果Y定义在名字空间M中，则在M中的自由函数中查找<br /><br />    另1：如果在一个步骤中找到多个合适的定义，则应用<font color="#0000ff" size="3">函数重载推理规则</font>来选择最佳匹配，<br />    此选择可能发现二义性定义<br /><br />    另2：这个规则只适用于操作符参数中至少含有一个非内置类型（<font color="#0000ff">user-defined type</font>）<br />    <font color="#ff0000"><font color="#0000ff">(typedef type is not user-defined type !)</font><br /><br />  </font>  <span style="font-weight: bold;"><br /></span><img src ="http://www.cppblog.com/SeerLee/aggbug/16065.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/SeerLee/" target="_blank">Seer_Lee</a> 2006-12-06 21:30 <a href="http://www.cppblog.com/SeerLee/articles/16065.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>