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

            Zero Lee的專欄

            頭文件中的名稱

            資料整理于《大規(guī)模C++程序設(shè)計(jì)》???
            ???在頭文件的文件作用域中聲明的名稱,可能潛在地與整個(gè)系統(tǒng)中任何一個(gè)文件的文件作用域名稱沖突。即使在一個(gè).cpp文件的文件作用域中聲明的帶有內(nèi)部連接的名稱也不能保證一定不與.h文件的作用域名稱沖突。
            ???主要設(shè)計(jì)規(guī)則:只有類、結(jié)構(gòu)、聯(lián)合和自由運(yùn)算符函數(shù)應(yīng)該在.h文件作用域內(nèi)聲明;只有類、結(jié)構(gòu)、聯(lián)合和內(nèi)聯(lián)函數(shù)成員或(內(nèi)聯(lián))自由運(yùn)算符應(yīng)該在.h文件的作用域內(nèi)定義。
            ???以下代碼段闡述了上述設(shè)計(jì)規(guī)則。

            ?1 // ?Driver.h????????????????????? // ?fine:comment
            ?2 #ifndef?INCLUDED_DRIVER????????? // ?fine:internal?include?guard
            ?3 #define ?INCLUDED_DIRVER
            ?4
            ?5 #ifndef?INCLUDED_NIFTY?????????? // ?fine:redundant?include?guard

            ?6 #include? " nifty.h "
            ?7 #endif
            ?8
            ?9 #define ?PI?3.141592????????????? // ?Avoid:macro?constant

            10 #define ?MIN(X)?((X)<(Y)?(X):(Y))? // ?Avoid:macro?constant
            11
            12 class ?ostream;??????????????? // ?fine:?class?dec.

            13 struct ?DriverInit;??????????? // ?fine:?class?dec.
            14 union?Uaw;??????????????????? // ?fine:?class?dec.
            15
            16 extern ? int ?globalVariable;? // ?Avoid:external?data?dec.
            17 static ? int ?fileScopeVariable;? // ?Avoid:internal?data?def.
            18 const ? int ?BUFFER_SIZE? = ? 256 ;? // ?Avoid:const?data?def.
            19 enum ?Boolean? {?zero,?one?} ;?? // ?Avoid:enumeration?at?file?scope
            20 typedef? long ?BigInt;????????? // ?typedef?at?file?scope
            21
            22 class ?Driver? {
            23 ??? enum ?Color? {?RED,?GREEN?} ;? // ?fine:enumeration?in?class?scope
            24 ???typedef? int ?(Dirver:: * PMF)();? // ?fine:?typedef?in?class?scope
            25 ??? static ? int ?s_count;?????? // ?fine:static?member?dec.
            26 ??? int ?d_size;???? // ?fine:?member?data?def.
            27
            28 private :
            29 ??? struct ?Pnt?
            {
            30 ?????? short ? int
            ?d_x,?d_y;
            31 ??????Pnt( int ?x,? int
            ?y)?
            32 ???????:?d_x(x),?d_y(y)? {?}

            33 ???}
            ;?????????????? // ?fine:?private?struct?def.
            34 ???friend?DirverInit;?? // ?fine:?friend?dec.
            35
            36 public :
            37 ??? int ? static ?round( double ?d);?? // ?fine:static?member?function?dec.

            38 ??? void ?setSize( int ?size);? // ?fine:?member?function?dec.
            39 ??? int ?cmp( const ?Driver & )? const ;? // ?fine:?const?member?function?dec.
            40 }
            ;??????????????? // ?fine:?class?def.
            41
            42 static ? class ?DriverInit? {
            43 ?? // ?

            44 }
            ?DriverInit;??? // ?Special?class
            45
            46 int ?min( int ?x,? int ?y);?? // ?Avoid:?free?function?dec.
            47
            48 inline? int ?max( int ?x,? int ?y)
            49
            {
            50 ??? return ?x? > ?y? ?
            ?x?:?y;
            51??? }
            ??? // ?Avoid?free?inline?function?def.
            52
            53 inline? void ?Driver::setSize( int ?size)?
            54
            {
            55 ???d_size? =
            ?size;
            56 }
            ???? // ?fine:?inline?member?function?def.
            57
            58 ostream & ? operator ? << (ostream & ?o,? const ?Dirver & ?d);?? // ?fine:?free?operator?function?def.
            59
            60 inline? int ? operator ? == ( const ?Driver & ?lhs,? const ?Dirver & ?rhs)?
            61
            {
            62 ??? return ?compare(lhs,?rhs)? == ? 0
            ;
            63 }
            ???? // ?fine:?free?inline?operator?func.?def.
            64
            65 inline? int ?Driver::round( double ?d)
            66
            {
            67 ???retrun?d? < ? 0 ? ? ? - int ( 0.5 ? - ?d)?:? int ( 0.5 ? +
            ?d);
            68 }
            ???? // ?fine:?inline?static?member?func.?def.
            69
            70 #endif
            71
            72

            posted on 2007-01-07 15:00 Zero Lee 閱讀(790) 評論(1)  編輯 收藏 引用 所屬分類: C++ Performance

            評論

            # re: 頭文件中的名稱 2007-05-25 15:10 morningstar

            good work!  回復(fù)  更多評論   

            国产69精品久久久久9999APGF| 九九热久久免费视频| 亚洲AV日韩AV永久无码久久| 亚洲国产精品无码久久久秋霞2| 9久久9久久精品| 一本一本久久a久久精品综合麻豆| 久久久久av无码免费网| 香蕉久久一区二区不卡无毒影院| 欧洲性大片xxxxx久久久| 浪潮AV色综合久久天堂| 久久亚洲国产精品123区| 久久久久久亚洲AV无码专区| 午夜精品久久久久9999高清| 99久久精品国产麻豆| 亚洲精品无码久久久久去q| 国内精品欧美久久精品| 国产成人久久精品激情| 伊人久久大香线蕉av一区| 久久国产成人午夜AV影院| 狠狠色丁香久久综合五月| 精品久久久中文字幕人妻 | 久久久久人妻一区精品色 | 亚洲人成无码www久久久| av无码久久久久不卡免费网站| 2019久久久高清456| 久久亚洲色一区二区三区| 青青青青久久精品国产| 久久不见久久见免费视频7| 国产精品久久久久久久久久影院| 久久精品国产精品亜洲毛片| 欧美精品一区二区精品久久| 久久综合久久综合久久| 久久久91精品国产一区二区三区| 久久精品国产亚洲AV高清热| 久久精品人妻中文系列| 亚洲AV日韩精品久久久久久| 欧美精品久久久久久久自慰| …久久精品99久久香蕉国产| 亚洲成色999久久网站| 久久亚洲天堂| 久久久久久夜精品精品免费啦|