• <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
            ??? 在一個非靜態(tài)的成員里面,this關鍵字就是一個指針,指向該函數的這次調用所針對的那個對象。
            ??? 在類X的非const成員函數里,this的類型就是X*,然而this并不是一個常規(guī)變量,不能獲取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
            謝謝你的指導,的確如你所說  回復  更多評論
              
            精品欧美一区二区三区久久久 | 国产成人无码久久久精品一| 伊人久久综合无码成人网| 久久综合亚洲欧美成人| 国产免费福利体检区久久| 一本久久知道综合久久| 国内精品久久久久久久影视麻豆| 精品久久久久久中文字幕大豆网| 亚洲精品高清国产一久久| 99久久国产综合精品女同图片| 伊人久久综在合线亚洲2019| 国产精品美女久久福利网站| 热re99久久精品国产99热| 伊人久久大香线蕉av不卡 | 国产精品久久久99| 99精品国产99久久久久久97 | 综合久久给合久久狠狠狠97色| 久久久久久久久无码精品亚洲日韩 | 久久er国产精品免费观看8| 97久久精品午夜一区二区| 国产精品久久久久a影院| 国产精品永久久久久久久久久 | 天天综合久久一二三区| 狠狠色丁香久久综合婷婷| 色综合久久无码中文字幕| 亚洲国产成人久久综合碰| 久久精品成人一区二区三区| 精品久久久久久中文字幕人妻最新 | 国产精品免费久久久久影院| 狠狠干狠狠久久| 精品国产乱码久久久久久1区2区 | 天堂久久天堂AV色综合 | 久久99精品久久久久久秒播| 久久亚洲国产欧洲精品一| 久久国产精品无码一区二区三区| 亚洲美日韩Av中文字幕无码久久久妻妇| 国产免费久久精品丫丫| 国产精品一区二区久久精品无码| 国产高清国内精品福利99久久| 国产ww久久久久久久久久| 国产精自产拍久久久久久蜜|