• <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的專欄

            編譯器何時(shí)為你產(chǎn)生默認(rèn)構(gòu)造函數(shù)

            總結(jié):
            ????有四種情況,會(huì)導(dǎo)致“編譯器必須為未聲明構(gòu)造函數(shù)的classes合成一個(gè)默認(rèn)構(gòu)造函數(shù)”。C++ 標(biāo)準(zhǔn)把那些合成物稱為隱含的有用默認(rèn)構(gòu)造函數(shù)。被合成出來(lái)的構(gòu)造函數(shù)只能滿足編譯器(非程序)的需要。它之所以能夠完成任務(wù),是借著“調(diào)用成員對(duì)象或基類的默認(rèn)構(gòu)造函數(shù)”或是“為每一個(gè)對(duì)象初始化其虛函數(shù)機(jī)制或虛基類機(jī)制”而完成的。至于沒有存在那四種情況而又沒有聲明構(gòu)造函數(shù)的類,我們說(shuō)它們擁有的是隱含的無(wú)用默認(rèn)構(gòu)造函數(shù),實(shí)際上它們并不被合成出來(lái)。
            ????在合成的默認(rèn)構(gòu)造函數(shù)中,只有基類子對(duì)象和成員對(duì)象會(huì)被初始化。所有其它的非靜態(tài)數(shù)據(jù)成員,如整數(shù)、整數(shù)指針、整數(shù)數(shù)組等等都不會(huì)被初始化。這些初始化操作對(duì)程序而言有需要,但對(duì)編譯器而言則沒必要。如果程序需要一個(gè)“把某指針設(shè)為0”的默認(rèn)構(gòu)造函數(shù),那么提供它的人應(yīng)該是程序員。
            ???
            ????C++新手一般有兩個(gè)常見的誤解:
            1)任何類如果沒有定義默認(rèn)構(gòu)造函數(shù),編譯器就會(huì)合成出它來(lái)。
            2)編譯器合成出來(lái)的默認(rèn)構(gòu)造函數(shù)會(huì)明確設(shè)定“類中每一個(gè)數(shù)據(jù)成員的默認(rèn)值”。

            正如你所見,上述兩個(gè)沒有一個(gè)是真的!
            -------------------------------------------------------------------------------------------
            Summary:?
            ???There are four characteristics of a class under which the compiler needs to synthesize a default constructor for classes that declare no constructor at all. The Standard refers to these as implicit, nontrivial default constructors. The synthesized constructor fulfills only an implementation need. It does this by invoking member object or base class default constructors or initializing the virtual function or virtual base class mechanism for each object. Classes that do not exhibit these characteristics and that declare no constructor at all are said to have implicit, trivial default constructors. In practice, these trivial default constructors are not synthesized.

            Within the synthesized default constructor, only the base class subobjects and member class objects are initialized. All other nonstatic data members, such as integers, pointers to integers, arrays of integers, and so on, are not initialized. These initializations are needs of the program, not of the implementation. If there is a program need for a default constructor, such as initializing a pointer to 0, it is the programmer's responsibility to provide it in the course of the class implementation.

            Programmers new to C++ often have two common misunderstandings:

            1)
            That a default constructor is synthesized for every class that does not define one
            2)
            That the compiler-synthesized default constructor provides explicit default initializers
            ?? for each data member declared within the class

            As you have seen, neither of these is true.

            --------------------------------------------------------------------------------------------

            posted on 2007-03-27 10:21 Zero Lee 閱讀(1062) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++ Performance

            久久精品人人做人人爽电影| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久人人爽人人爽人人片AV麻烦| 久久综合亚洲色HEZYO国产| 亚洲日韩欧美一区久久久久我| 一本综合久久国产二区| 99久久精品国产一区二区| 久久久久久狠狠丁香| 亚洲&#228;v永久无码精品天堂久久| 中文精品久久久久人妻| 国产成人精品免费久久久久| 久久精品成人免费国产片小草| 久久久黄色大片| 久久亚洲欧美日本精品| 亚洲综合精品香蕉久久网| 国产精品亚洲美女久久久| 久久香蕉超碰97国产精品| 久久毛片免费看一区二区三区| 精品少妇人妻av无码久久| 久久综合亚洲色一区二区三区| av色综合久久天堂av色综合在| 久久久精品免费国产四虎| av色综合久久天堂av色综合在| 精品免费久久久久国产一区| 久久精品国产99久久无毒不卡| 亚洲欧美日韩精品久久亚洲区 | 91久久成人免费| 一本色道久久综合狠狠躁| 久久精品国产清自在天天线| 久久精品国产亚洲综合色 | 国产亚洲精午夜久久久久久| 国产亚洲精久久久久久无码| 亚洲αv久久久噜噜噜噜噜| 亚洲午夜无码AV毛片久久| 亚洲国产成人精品女人久久久 | 人妻少妇久久中文字幕一区二区| 久久91精品国产91| 精品国产乱码久久久久软件| 久久久久99这里有精品10| 狠狠色综合网站久久久久久久高清| 亚洲国产综合久久天堂|