zoukankan      html  css  js  c++  java
  • c++——this指针

     

     类的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 }
  • 相关阅读:
    linux 磁盘管理学习笔记
    Apache的Order Allow Deny心得
    NodeJs 笔记
    JavaScript 笔记
    MySQL 学习笔记
    HTML 转义符
    UTF-8 BOM(EF BB BF)
    [ Python
    [ Python
    [ Python
  • 原文地址:https://www.cnblogs.com/long5683/p/9775300.html
Copyright © 2011-2022 走看看