• <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 探丫頭 閱讀(2376) 評(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所以兩邊都不能修改  回復(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)論
              
            久久久国产精品| 狠狠久久亚洲欧美专区| 深夜久久AAAAA级毛片免费看| 国产精品综合久久第一页| 四虎国产精品免费久久5151| 精品视频久久久久| 久久久无码精品亚洲日韩京东传媒| 久久九九久精品国产| 99热都是精品久久久久久| 伊人伊成久久人综合网777| 99久久精品费精品国产一区二区| 久久国产综合精品五月天| 一级A毛片免费观看久久精品| 色99久久久久高潮综合影院| 欧美亚洲国产精品久久高清| 久久精品国产亚洲AV无码偷窥| 狠狠精品久久久无码中文字幕| 亚洲人成伊人成综合网久久久| 九九久久自然熟的香蕉图片| 久久国产高清一区二区三区| 亚洲色欲久久久综合网东京热| 久久涩综合| 91久久精品国产成人久久| 亚洲欧美成人久久综合中文网 | 亚洲欧洲中文日韩久久AV乱码| 色综合久久久久综合体桃花网| 国产福利电影一区二区三区久久老子无码午夜伦不 | 国产V综合V亚洲欧美久久| 四虎久久影院| 精品久久久久中文字| 色综合久久最新中文字幕| 久久综合欧美成人| 久久―日本道色综合久久| 国产亚洲美女精品久久久久狼| 亚洲AV无码一区东京热久久| 久久久久人妻一区精品果冻| 女人香蕉久久**毛片精品| 热re99久久6国产精品免费| 中文国产成人精品久久不卡| 一级a性色生活片久久无| 久久影视国产亚洲|