前言
C++this常见用法
Code
this是指向当前对象的指针
# include <iostream>
using namespace std;
class Student{
public:
Student(string name,int age);
void show();
private:
string name;
int age;
};
Student::Student(string name, int age){
this->name = name;
this->age = age;
}
void Student::show(){
cout << name << age << endl;
}
int main(){
Student stu("zhangsan",23);
stu.show();
return 0;
}