这个程序怎么理解

来源:百度知道 编辑:UC知道 时间:2024/05/30 12:56:36
关于c++ operator=重载:
//......
CAT & operator=(const CAT &);
//......
CAT & CAT::operator=(const CAT &rhs)
{
if (this==&rhs)
return *this;
*itsage=rhs.getage();
return *this;
}
这两个return *this;分别是什么意思?

//你问的模糊,能说多少说多少吧
CAT & operator=(const CAT &); //这是声明

CAT & CAT::operator=(const CAT &rhs) //这是定义
{
if (this==&rhs) //假设程序中有A=B,AB为对象,如果两个对象一样就直接返回
return *this;
*itsage=rhs.getage(); //否则将B对象中的age赋给A对象的age
return *this;
}
//return *this .就是把本对象返回去,CAT &...这是要返回值的