大家好.各位能否给我详细讲以下vc中this的含义及用法,书上讲的不十分清楚,我一直搞不明白.

解决方案 »

  1.   

    this
    C++ Specific —>The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.When a nonstatic member function is called for an object, the address of the object is passed as a hidden argument to the function. For example, the following function callmyDate.setMonth( 3 );
    can be interpreted this way:setMonth( &myDate, 3 );
    The object's address is available from within the member function as the this pointer. It is legal, though unnecessary, to use the this pointer when referring to members of the class.The expression (*this) is commonly used to return the current object from a member function.Note   Modifying the this pointer is illegal in the latest version of C++.END C++ SpecificExample// Example of the this pointer
    void Date::setMonth( int mn )
    {
       month = mn;            // These three statements
       this->month = mn;      //     are equivalent
       (*this).month = mn;
    }
      

  2.   

    也就是指向对象本身的指针。
    例如在一个dialog中this表示指向该对话框的指针,然后你可以使用this->来调用其中的成员变量、成员函数等。
    一般来说用的不多。在对象内部直接可以用成员变量、成员函数的名字就OK。
      

  3.   

    this
    C++ Specific —>The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.When a nonstatic member function is called for an object, the address of the object is passed as a hidden argument to the function. For example, the following function callmyDate.setMonth( 3 );
    can be interpreted this way:setMonth( &myDate, 3 );
    The object's address is available from within the member function as the this pointer. It is legal, though unnecessary, to use the this pointer when referring to members of the class.The expression (*this) is commonly used to return the current object from a member function.Note   Modifying the this pointer is illegal in the latest version of C++.END C++ SpecificExample// Example of the this pointer
    void Date::setMonth( int mn )
    {
       month = mn;            // These three statements
       this->month = mn;      //     are equivalent
       (*this).month = mn;
    }
      

  4.   

    this其实是c++中的概念,意思是当前对象本身
      

  5.   

    很简单,你声明一个类的对象,在程序执行进入到类的成员函数后,this代表该对象所在的地址
      

  6.   

    msdn中说的很明白:
    this
    C++ Specific —>The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.When a nonstatic member function is called for an object, the address of the object is passed as a hidden argument to the function. For example, the following function callmyDate.setMonth( 3 );
    can be interpreted this way:setMonth( &myDate, 3 );
    The object's address is available from within the member function as the this pointer. It is legal, though unnecessary, to use the this pointer when referring to members of the class.The expression (*this) is commonly used to return the current object from a member function.Note   Modifying the this pointer is illegal in the latest version of C++.END C++ SpecificExample// Example of the this pointer
    void Date::setMonth( int mn )
    {
       month = mn;            // These three statements
       this->month = mn;      //     are equivalent
       (*this).month = mn;
    }
      

  7.   

    this表示指向自己的指针
    void CMyPage :: ShowPopDlg()
    {
        ...
        CPopDlg dlgPop(iType, this); //将自己(CMyPage对象)传给CPopDlg
        ...
    }
      

  8.   

    就是本身。在the c++ programming language 或c++ prime 中讲的很清楚。你可以去看看。
      

  9.   

    this指针就指向对象本身的指针
    如下:class classx{
          private:int data;
                  int func1(int x);      //等价于fun1(classx* this,int x)
          public:
                  int func2(int y);      //等价于fun2(classx* this,int y)   classx* this 由编译系统给出
                 }
    classx obj;
     obj.fun2(y);等价于obj.fun2(this,y);
    调用一个成员函数或成员数据需知道对象的地址和成员的偏移量
      

  10.   

    你随便使用VC建个框架,对话框,最简单的那种,再类中找个地方,比如InitDialog中,SetWindowText("gggggggggggg");
    和this->SetWindowText("ggggggggggggg");并没有区别,就是对象本身的指针,一般用不用关系不大