首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

这个程序如何理解

2012-02-10 
这个程序怎么理解classCAT{public://......CAT&operator(constCAT&)//......private:int*itsage}CAT&CA

这个程序怎么理解
class   CAT
{
public:
//......  
CAT   &   operator=(const   CAT   &);  
//......
private:
int   *itsage;  
}
CAT   &   CAT::operator=(const   CAT   &rhs)  
{  
if   (this==&rhs)  
return   *this;  
*itsage=rhs.getage();  
return   *this;  
}
这两个return   *this;分别是什么意思?

[解决办法]
this是一个指针 指向当前类对象
if (this==&rhs) //如果当前类对象与要等于的对象是同一个对象 直接返回当前对象
return *this;
*itsage=rhs.getage(); //如果当前类对象与要等于的对象不同 将当前类对象赋值 并返回当前类对象指针
return *this;

热点排行