#include <iostream>
using namespace std;
struct Person {
int m_age;
void run() { // 函数的代码都在代码区
cout << "Person::run() - " << m_age << endl;
}
};
int main() { // 函数的代码都在代码区
Person person1; //局部变量,栈空间
person1.m_age = 10;
person1.run();
Person person2; //局部变量,栈空间
person2.m_age = 20;
person2.run();
getchar();
return 0;
}
void run() { //隐式参数,this偷偷给函数传了一个指针地址的参数
cout << "person::run() - " << this->m_age << endl; //谁调用run()函数,this就访问谁
}
person1.run();
// this = &person1 this存的是&person1的指针
原文:https://www.cnblogs.com/sec875/p/12266711.html