• <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

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


            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()函數(shù)引用的是全局?jǐn)?shù)據(jù). 所以早期的C++程序員發(fā)明了倆防范寫法(至今還有人用):
            (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.(數(shù)據(jù)成員定義還是要放在最前面)

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

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理



            <2006年4月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            常用鏈接

            留言簿(7)

            隨筆檔案

            最新隨筆

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            国产美女久久精品香蕉69| 一级做a爰片久久毛片16| 久久人人超碰精品CAOPOREN| 久久久久亚洲AV成人网| 久久综合给合综合久久| 久久久久久国产a免费观看黄色大片 | 亚洲国产综合久久天堂| 伊人久久大香线蕉AV一区二区| 国内精品久久久久久中文字幕 | 久久精品日日躁夜夜躁欧美| 久久99精品久久久久久久久久| 久久九九有精品国产23百花影院| 亚洲人成无码www久久久| 国产精品久久成人影院| 久久精品国产亚洲一区二区三区 | 国产美女久久久| 免费久久人人爽人人爽av| 91久久精一区二区三区大全| 色诱久久av| 91精品国产综合久久香蕉| 久久婷婷国产剧情内射白浆| AA级片免费看视频久久| 久久人人爽人人人人爽AV| 成人精品一区二区久久久| 色婷婷综合久久久中文字幕| 人妻丰满?V无码久久不卡| 久久精品国产91久久综合麻豆自制 | 欧洲人妻丰满av无码久久不卡| www久久久天天com| 狠狠色婷婷久久一区二区| 色综合久久88色综合天天 | 国产精品综合久久第一页| 国产精品久久久久影院色| 少妇熟女久久综合网色欲| 欧美伊人久久大香线蕉综合69| 国产成人精品久久综合 | 久久精品毛片免费观看| 一本色道久久88精品综合| 欧美性大战久久久久久| 色婷婷久久久SWAG精品| 久久久无码精品午夜|