| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 981 人关注过本帖
标题:关于运算符重载
取消只看楼主 加入收藏
endless
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-8-3
收藏
 问题点数:0 回复次数:1 
关于运算符重载
在《Thinking in  C++》中的一段代码如下:
#include<iostream>
using namespace std ;
class  integer
{
  int i ;
  public:
      integer(int ii):i(ii){}
      const integer
      operator+(const integer&rv)const
      {
       cout<<"operrater+"<<endl;
       return integer(i+rv.i);
      }
  integer&
      operator+=(const integer&rv)
  {
      cout<<"operater +="<<endl ;
      i+=rv.i ;
      return *this ;
  }

};
     int main()
     {
         cout<<"buit-in types:"<<endl;
         int i=1,j=2,k=3 ;
         k+=i+j;
         cout<<"user-defined types:"<<endl;
         integer ii(1),jj(2),kk(3) ;
         kk+=ii+jj ;
    
     }  

一直对代码里return *this ,这个*this指针不了解,还有为什么需要在public定义const integer 它的作用是什么
?谢谢解答了~
搜索更多相关主题的帖子: 运算符 重载 
2008-08-05 17:59
endless
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-8-3
收藏
得分:0 
回复 3# lovelifeVC 的帖子
受教了 谢谢解答
2008-08-09 11:48
快速回复:关于运算符重载
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015609 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved