• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-34  評論-108  文章-0  trackbacks-0
            ??? 在一個非靜態的成員里面,this關鍵字就是一個指針,指向該函數的這次調用所針對的那個對象。
            ??? 在類X的非const成員函數里,this的類型就是X*,然而this并不是一個常規變量,不能獲取this的地址或者給它賦值。
            ??? 在類X的const成員函數里,this的類型就是const X*,以防止對這個對象本身的修改。
            posted on 2007-02-10 11:12 探丫頭 閱讀(2376) 評論(4)  編輯 收藏 引用 所屬分類: 編程語言——C++

            評論:
            # re: this指針 2007-02-10 11:19 | nono
            獲取this指針的地址是可以的;)
            而且在類X的非const成員函數里,this的類型應該是X* const,所以可以修改this說指向的地址的值的內容,而不能修改自身;
            在類X的const成員函數里,則是const X * const所以兩邊都不能修改  回復  更多評論
              
            # re: this指針 2007-02-10 13:01 | 平凡小草
            C++標準的確就是我文章中這樣說的  回復  更多評論
              
            # re: this指針 2007-02-10 14:42 | nono
            查了下,還真的有,不過你用編譯器試試就可以知道了
            In the body of a nonstatic (9.3) member function, the keyword this is a non-lvalue expression whose
            value is the address of the object for which the function is called. The type of this in a member function
            of a class X is X*. If the member function is declared const, the type of this is const X*, if the member
            function is declared volatile, the type of this is volatile X*, and if the member function is
            declared const volatile, the type of this is const volatile X*.

            [測試代碼]
            #include <iostream>
            using namespace std;
            class Test
            {
            public:
            void print();
            void print_const() const;
            };

            void Test::print()
            {
            cout << this << endl;
            this = 1;
            }

            void Test::print_const() const
            {
            cout << this << endl;
            this = 1;
            };

            int main()
            {
            return 0;
            }

            [編譯錯誤]
            main.cpp(13) : error C2440: '=' : cannot convert from 'int' to 'Test *const '
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
            main.cpp(19) : error C2440: '=' : cannot convert from 'int' to 'const Test *const '
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

            VC6.0,2005都是一樣,G++提示non-lvalue in assignment
            正如C++標準草案中寫的,the keyword this is a non-lvalue expression ,它是不能進行賦值的  回復  更多評論
              
            # re: this指針 2007-02-10 14:47 | 平凡小草
            @nono
            謝謝你的指導,的確如你所說  回復  更多評論
              
            色欲综合久久中文字幕网 | 国产精品热久久毛片| 97超级碰碰碰久久久久| 久久久综合九色合综国产| 91精品婷婷国产综合久久| 久久久久婷婷| 国产亚洲欧美精品久久久| 久久av高潮av无码av喷吹| 亚洲精品乱码久久久久66| 91精品观看91久久久久久| 2020久久精品亚洲热综合一本| 久久亚洲日韩精品一区二区三区| 国产精品美女久久久久av爽| 一本久久a久久精品亚洲| 91久久九九无码成人网站| 狠狠色丁香婷婷久久综合五月| 久久99热精品| 香蕉久久av一区二区三区| 青草久久久国产线免观| 青青热久久综合网伊人| 久久精品国产久精国产果冻传媒 | 日韩欧美亚洲综合久久| 国产精品久久国产精麻豆99网站| 久久91精品国产91| 色天使久久综合网天天| 色综合久久综精品| 国产一区二区三区久久| 亚洲av成人无码久久精品| 国产精品成人久久久| 午夜精品久久影院蜜桃| 久久久久国产一级毛片高清板| 久久99国产精一区二区三区| 精品少妇人妻av无码久久| 亚洲va中文字幕无码久久不卡| 日日狠狠久久偷偷色综合0 | 亚洲欧美国产日韩综合久久| 国产一区二区精品久久岳| 狠狠狠色丁香婷婷综合久久俺| 国产精品99久久99久久久| 久久精品毛片免费观看| aaa级精品久久久国产片|