• <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>
            asm, c, c++ are my all
            -- Core In Computer
            posts - 139,  comments - 123,  trackbacks - 0

            /********************************************\
            |????歡迎轉載, 但請保留作者姓名和原文鏈接, 祝您進步并共勉!???? |
            \********************************************/


            C++對象模型(9) - 3.1 The Binding of a Data Member

            作者: Jerry Cat
            時間: 2006/11/15
            鏈接:?
            http://www.shnenglu.com/jerysun0818/archive/2006/11/15/15186.html


            3.1 The Binding of a Data Member

            Consider the following program fragment:.

            // A third party foo.h header file
            // pulled in from somewhere
            extern float x;

            // the programmer's Point3d.h file
            class Point3d
            {
            public:
            ?? Point3d( float, float, float );
            ?? // question:? which x is returned and set?
            ?? float X() const { return x; }
            ?? void X( float new_x ) const { x = new_x; }
            ?? // ...
            private:
            ?? float x, y, z;
            };
            If I were to ask which x the Point3d member X() returns—the class instance or the extern instance—everyone today would answer the class instance, and everyone would be right. Most everyone, however, would probably be surprised to learn that this answer was not always correct.

            早期的C++將其解析為X()函數引用的是全局數據. 所以早期的C++程序員發明了倆防范寫法(至今還有人用):
            (1). Placing all data members first in the class declaration to ensure the right binding:

            class Point3d
            {
            ?? // defensive programming style #1
            ?? // place all data first ...
            ?? float x, y, z;
            public:
            ?? float X() const { return x; }
            ?? // ... etc. ...
            };

            (2). Placing all inline functions, regardless of their size, outside the class declaration:

            class Point3d
            {
            public:
            ?? // defensive programming style #2
            ?? // place all inlines outside the class
            ?? Point3d();
            ?? float X() const;
            ?? void X( float ) const;
            ?? // ... etc. ...
            };
            inline float
            Point3d::
            X() const
            {
            ?? return x;
            }

            // ... etc. ...


            extern int x;

            class Point3d
            {
            public:
            ?? ...
            ?? // analysis of function body delayed until
            ?? // closing brace of class declaration seen.
            ?? float X() const { return x; }
            ?? ...
            private:
            ?? float x;
            ?? ...
            };

            // in effect, analysis is done here
            the analysis of the member function's body is delayed until the entire class declaration is seen. Thus the binding of a data member within the body of an inline member function does not occur until after the entire class declaration is seen.

            但是This is not true of the argument list of the member function, however. Names within the argument list are still resolved in place at the point they are first encountered. Nonintuitive bindings between extern and nested type names, therefore, can still occur. In the following code fragment, for example, the type of length in both member function signatures resolves to that of the global typedef—that is, to int. When the subsequent declaration of the nested typedef of length is encountered, the Standard requires that the earlier bindings be flagged as illegal:

            typedef int length;

            class Point3d
            {
            public:
            ?? // oops: length resolves to global
            ?? // ok: _val resolves to Point3d::_val
            ?? mumble( length val ) { _val = val; }
            ?? length mumble() { return _val; }
            ?? // ...

            private:
            ?? // length must be seen before its first
            ?? // reference within the class.? This
            ?? // declaration makes the prior reference illegal.
            ?? typedef float length;
            ?? length _val;
            ?? // ...
            };
            This aspect of the language still requires the general defensive programming style of always placing nested type declarations at the beginning of the class. In our example, placing the nested typedef defining length above any of its uses within the class corrects the nonintuitive binding.(數據成員定義還是要放在最前面)

            posted on 2006-11-15 17:04 Jerry Cat 閱讀(481) 評論(0)  編輯 收藏 引用

            <2006年11月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            常用鏈接

            留言簿(7)

            隨筆檔案

            最新隨筆

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            伊人久久大香线蕉av不变影院| 久久香蕉综合色一综合色88| 亚洲国产小视频精品久久久三级| 大蕉久久伊人中文字幕| 欧美亚洲另类久久综合婷婷 | 国产精品99久久久精品无码| 亚洲午夜福利精品久久| 成人久久综合网| 中文精品久久久久人妻| …久久精品99久久香蕉国产| 无码精品久久一区二区三区| 色综合久久久久综合体桃花网| 亚洲精品高清国产一久久| 狠狠色丁香久久婷婷综合| 26uuu久久五月天| 欧美牲交A欧牲交aⅴ久久| 久久久91人妻无码精品蜜桃HD | 久久久久国产一级毛片高清版| 久久综合色之久久综合| 国内精品久久久久久99蜜桃| 亚洲国产天堂久久久久久| 久久99精品国产99久久6| 久久棈精品久久久久久噜噜| www.久久热.com| 麻豆成人久久精品二区三区免费 | 丁香五月网久久综合| 久久精品国产亚洲av麻豆蜜芽| 久久久91精品国产一区二区三区| 久久久久久精品成人免费图片| 久久久久亚洲?V成人无码| AAA级久久久精品无码区| 麻豆精品久久精品色综合| 久久99精品综合国产首页| 亚洲乱码中文字幕久久孕妇黑人| 久久精品一区二区三区中文字幕| 国产成人久久精品区一区二区| 久久人人爽人人爽人人片av高请 | 88久久精品无码一区二区毛片| 狠狠色丁香久久婷婷综合五月| 久久精品国产亚洲AV大全| 久久国产精品成人影院|