类的this指针就是值类的对象自己
实验1:若类成员函数的形参 和 类的属性,名字相同,通过this指针来解决。
1 #include <iostream> 2 using namespace std; 3 class Test 4 { 5 public: 6 Test(int a, int b) //---> Test(Test *this, int a, int b) 7 { 8 this->a = a; 9 this-> b = b; 10 } 11 void printT() 12 { 13 cout<<"a: " <<a <<endl; 14 cout<< "b: " << this->b <<endl; 15 } 16 protected: 17 private: 18 int a; 19 int b; 20 }; 21 22 void main() 23 { 24 25 Test t1(1, 2); 26 t1.printT();// ===> printT(&t1) 27 cout<<"hello..."<<endl; 28 system("pause"); 29 return ; 30 }