this指针就是类的函数中区分多个对象共用的成员函数。
例子1
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
char name[50];
int num;
int age;
public:
void set_age(int age)
{
this-> age= age;
};
};
int main() {
Student stud = { 0 };
stud.set_age (20);
cout << "stud.age = " << stud.age << endl;
system("pause");
return 0;
}