【发布时间】:2014-06-27 14:21:09
【问题描述】:
我的问题是指我想调用同一类的其他方法的情况。使用和不使用“this”的区别在哪里?与类的变量相同。通过“this”访问这些变量有区别吗?是否与这些方法/变量是否为私有/公共有关?示例:
class A {
private:
int i;
void print_i () { cout << i << endl; }
public:
void do_something () {
this->print_i(); //call with 'this', or ...
print_i(); //... call without 'this'
this->i = 5; //same with setting the member;
i = 5;
}
};
【问题讨论】: