• <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 探丫頭 閱讀(2379) 評論(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久久香蕉国产色戒 | 国产精品久久久久久一区二区三区| 久久ZYZ资源站无码中文动漫 | 国产精品伊人久久伊人电影| 日韩欧美亚洲综合久久影院Ds| 久久久久av无码免费网| 99久久精品免费看国产免费| 国内高清久久久久久| 国内精品久久久久久久亚洲| 欧美黑人激情性久久| 伊人久久大香线蕉精品不卡 | 国产A级毛片久久久精品毛片| 99久久精品国产麻豆| 亚洲精品蜜桃久久久久久| 久久久久久国产精品无码下载 | 久久精品国产亚洲av水果派| 国产精品久久婷婷六月丁香| 久久av免费天堂小草播放| 久久99精品国产99久久6男男| 一本色道久久综合狠狠躁| 久久夜色撩人精品国产| 99久久亚洲综合精品成人| 久久99精品久久久久子伦| 伊人久久大香线蕉亚洲| 人妻中文久久久久| 一本一道久久a久久精品综合| 国内精品久久久久久久亚洲| 日韩一区二区久久久久久| 国产精品18久久久久久vr| 东京热TOKYO综合久久精品| 99久久99这里只有免费费精品| 久久久亚洲裙底偷窥综合| 一本大道久久东京热无码AV| 久久精品?ⅴ无码中文字幕| 精品久久久久久无码人妻热| 久久久久亚洲AV综合波多野结衣| 久久久人妻精品无码一区| 久久无码专区国产精品发布| 久久精品国产免费观看| 精品熟女少妇av免费久久|