C++ this 指针
在 C++ 中,每一个对象都能通过 this 指针来访问自己的地址。this 指针是所有成员函数的隐含参数。因此,在成员函数内部,它可以用来指向调用对象。
友元函数没有 this 指针,因为友元不是类的成员。只有成员函数才有 this 指针。
class Box {
public:
int compare(Box box) {
return this->Volume() > box.Volume();
}
};
运行结果 / 调试信息
等待编译...
Graph loading...
0 / 0