C++ 问题

chongchong

知名会员
注册
2003-11-04
消息
163
荣誉分数
0
声望点数
126
class X {
public:
void A();
void B();
};

void X::A() {
}

void X::B() {
this->A(); // 在什么情况下要这样写 ???
}
 
You do not need this-> at all. You may want to use it in case a super class Y of X has A().

class Y
{
public:
void A();
};

class X : public Y
{
public:
void A();
void B();
}

void X::B()
{
this->A(); //function call in current class
Y::A(); //function call in super class
}

in this case you only want to show the difference although this-> is unnecessary.
 
后退
顶部