• <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  評(píng)論-108  文章-0  trackbacks-0
            ??? 在一個(gè)非靜態(tài)的成員里面,this關(guān)鍵字就是一個(gè)指針,指向該函數(shù)的這次調(diào)用所針對(duì)的那個(gè)對(duì)象。
            ??? 在類(lèi)X的非const成員函數(shù)里,this的類(lèi)型就是X*,然而this并不是一個(gè)常規(guī)變量,不能獲取this的地址或者給它賦值。
            ??? 在類(lèi)X的const成員函數(shù)里,this的類(lèi)型就是const X*,以防止對(duì)這個(gè)對(duì)象本身的修改。
            posted on 2007-02-10 11:12 探丫頭 閱讀(2379) 評(píng)論(4)  編輯 收藏 引用 所屬分類(lèi): 編程語(yǔ)言——C++

            評(píng)論:
            # re: this指針 2007-02-10 11:19 | nono
            獲取this指針的地址是可以的;)
            而且在類(lèi)X的非const成員函數(shù)里,this的類(lèi)型應(yīng)該是X* const,所以可以修改this說(shuō)指向的地址的值的內(nèi)容,而不能修改自身;
            在類(lèi)X的const成員函數(shù)里,則是const X * const所以?xún)蛇叾疾荒苄薷?nbsp; 回復(fù)  更多評(píng)論
              
            # re: this指針 2007-02-10 13:01 | 平凡小草
            C++標(biāo)準(zhǔn)的確就是我文章中這樣說(shuō)的  回復(fù)  更多評(píng)論
              
            # re: this指針 2007-02-10 14:42 | nono
            查了下,還真的有,不過(guò)你用編譯器試試就可以知道了
            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*.

            [測(cè)試代碼]
            #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;
            }

            [編譯錯(cuò)誤]
            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++標(biāo)準(zhǔn)草案中寫(xiě)的,the keyword this is a non-lvalue expression ,它是不能進(jìn)行賦值的  回復(fù)  更多評(píng)論
              
            # re: this指針 2007-02-10 14:47 | 平凡小草
            @nono
            謝謝你的指導(dǎo),的確如你所說(shuō)  回復(fù)  更多評(píng)論
              
            国产情侣久久久久aⅴ免费| 久久国产高清字幕中文| 免费一级做a爰片久久毛片潮 | 久久精品国产久精国产果冻传媒 | 久久综合视频网| 中文字幕乱码久久午夜| 99久久国产热无码精品免费| 久久久久久国产精品免费免费| 久久一日本道色综合久久| 亚洲成色999久久网站| 久久天天躁狠狠躁夜夜不卡| 久久亚洲精品成人AV| 午夜精品久久影院蜜桃| 久久久久久国产精品无码超碰| 久久综合伊人77777| 久久香蕉综合色一综合色88| 国产精品久久久久蜜芽| 国产成人久久久精品二区三区| 久久香综合精品久久伊人| 伊人情人综合成人久久网小说 | 日产久久强奸免费的看| 久久青草国产手机看片福利盒子 | 国产精品成人99久久久久| 久久精品国产清高在天天线| 亚洲国产综合久久天堂| 久久嫩草影院免费看夜色| 四虎国产精品免费久久久| 97超级碰碰碰久久久久| 久久人人爽人人爽人人AV东京热| 午夜精品久久久久| 久久夜色精品国产www| 久久91这里精品国产2020| 狠色狠色狠狠色综合久久 | 久久强奷乱码老熟女网站| 国产精品一区二区久久精品无码 | 精品乱码久久久久久夜夜嗨| 一级做a爱片久久毛片| 久久国产精品-久久精品| 久久精品亚洲一区二区三区浴池 | 综合久久给合久久狠狠狠97色| 人妻中文久久久久|