﻿<?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++博客-李小生-最新评论</title><link>http://www.cppblog.com/harry-li/CommentsRSS.aspx</link><description>You can call me Harry!</description><language>zh-cn</language><pubDate>Tue, 09 May 2006 14:19:06 GMT</pubDate><lastBuildDate>Tue, 09 May 2006 14:19:06 GMT</lastBuildDate><generator>cnblogs</generator><item><title>re: 关于资源和操作符重载疑问</title><link>http://www.cppblog.com/harry-li/archive/2006/04/23/6055.html#6105</link><dc:creator>Harry</dc:creator><author>Harry</author><pubDate>Sun, 23 Apr 2006 12:41:00 GMT</pubDate><guid>http://www.cppblog.com/harry-li/archive/2006/04/23/6055.html#6105</guid><description><![CDATA[多谢大哥了，呵呵<br><br>这段代码是随手写的，也没仔细校验了。要不断学习啊！呵呵<img src ="http://www.cppblog.com/harry-li/aggbug/6105.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/harry-li/" target="_blank">Harry</a> 2006-04-23 20:41 <a href="http://www.cppblog.com/harry-li/archive/2006/04/23/6055.html#6105#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 关于资源和操作符重载疑问</title><link>http://www.cppblog.com/harry-li/archive/2006/04/22/6055.html#6063</link><dc:creator>芋头</dc:creator><author>芋头</author><pubDate>Fri, 21 Apr 2006 16:56:00 GMT</pubDate><guid>http://www.cppblog.com/harry-li/archive/2006/04/22/6055.html#6063</guid><description><![CDATA[＝操作符一般还要返回该对象的引用。＋操作符最好写成全局的，不要作为成员函数，好处下面解释。另外代码似乎充满了C＃或JAVA代码风格，错误很多，还是先搞清C＋＋语法再做吧，每种语言都有它的特色。我简单整理了一下：<br>class SimpleClass<br>{<br>	friend SimpleClass operator + (const SimpleClass&amp; lhs, const SimpleClass&amp; rhs);<br>public :<br>	SimpleClass(int value = 0);<br>	SimpleClass&amp; operator = (const SimpleClass&amp; right);<br><br>	int  m_iValue;<br>} ;<br><br>SimpleClass::SimpleClass(int value)<br>:m_iValue(value)<br>{<br>}<br><br>SimpleClass&amp;  SimpleClass::operator = (const SimpleClass&amp; right)<br>{<br>	m_iValue = right.m_iValue;<br>	return *this;<br>} <br><br>SimpleClass operator + (const SimpleClass&amp; lhs, const SimpleClass&amp; rhs)<br>{<br>	return SimpleClass(lhs.m_iValue + rhs.m_iValue);<br>}<br><br>int  main()<br>{<br>	SimpleClass sc1( 1 );<br>	SimpleClass sc2( 2 );<br>	SimpleClass sc3;<br><br>	sc3 = sc1 + sc2;<br>	sc3 = sc1 + 1;<br>	sc3 = 1 + sc1;<br><br>	return   0 ;<br>} <br>上面所说的好处就是，sc3 = sc1 + 1; 和sc3 = 1 + sc1这2个都可以成立了，如果写成成员函数，则后一个不能编译。<img src ="http://www.cppblog.com/harry-li/aggbug/6063.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/harry-li/" target="_blank">芋头</a> 2006-04-22 00:56 <a href="http://www.cppblog.com/harry-li/archive/2006/04/22/6055.html#6063#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 关于资源和操作符重载疑问</title><link>http://www.cppblog.com/harry-li/archive/2006/04/22/6055.html#6061</link><dc:creator>芋头</dc:creator><author>芋头</author><pubDate>Fri, 21 Apr 2006 16:38:00 GMT</pubDate><guid>http://www.cppblog.com/harry-li/archive/2006/04/22/6055.html#6061</guid><description><![CDATA[+操作符返回一个临时对象，不要去new，返回类型不是引用类型，剩下的就好写了。<img src ="http://www.cppblog.com/harry-li/aggbug/6061.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/harry-li/" target="_blank">芋头</a> 2006-04-22 00:38 <a href="http://www.cppblog.com/harry-li/archive/2006/04/22/6055.html#6061#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>