怎样使用this 关键字

来源:百度知道 编辑:UC知道 时间:2024/05/26 14:01:21
我希望能够详细的,有个实例

this 是指针,用在class的成员函数里,(或结构的成员函数里),指向调用函数的class的对象。

在class的成员函数里,(*this) 用于送返class对象。

实例
// Example of the this pointer
void Date::setMonth( int mn )
{
month = mn; // 这3 句,完全等价。
this->month = mn;
(*this).month = mn;
}