<分区>
这有什么区别:
int MyClass::getId() {
return this->id;
}
还有这个:
int MyClass::getId() {
return id;
}
在 C++ 中?
<分区>
这有什么区别:
int MyClass::getId() {
return this->id;
}
还有这个:
int MyClass::getId() {
return id;
}
在 C++ 中?
最佳答案
第一个示例将查找名称“id”的范围限制为类 MyClass 的成员。
第二个例子没有。
这会有所不同,例如MyClass 没有成员“id”,或者当前方法是否有同名的局部变量或参数。
关于c++ - C++中的this->member VS member,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31373225/