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

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

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

            正如你所見,上述兩個沒有一個是真的!
            -------------------------------------------------------------------------------------------
            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 閱讀(1063) 評論(0)  編輯 收藏 引用 所屬分類: C++ Performance

            麻豆亚洲AV永久无码精品久久| 日本久久久久亚洲中字幕| 伊人丁香狠狠色综合久久| 久久人人爽人人爽AV片| 囯产精品久久久久久久久蜜桃 | 成人免费网站久久久| 品成人欧美大片久久国产欧美| 人人妻久久人人澡人人爽人人精品 | 久久亚洲AV成人出白浆无码国产 | 久久精品桃花综合| 国产精品一区二区久久不卡| 精品水蜜桃久久久久久久| 欧美午夜精品久久久久免费视| 久久黄色视频| 2022年国产精品久久久久| 久久99热这里只频精品6| 曰曰摸天天摸人人看久久久| 午夜精品久久久久久中宇| 欧美激情精品久久久久久久| 亚洲国产天堂久久综合网站| 久久精品人人做人人妻人人玩| 怡红院日本一道日本久久| 国产精品99久久99久久久| 99久久国产宗和精品1上映| 久久免费香蕉视频| 久久精品二区| 国内精品久久久久久久影视麻豆| 国产日产久久高清欧美一区| 大伊人青草狠狠久久| 国产成人精品久久免费动漫| 亚洲精品乱码久久久久66| 精品久久人人爽天天玩人人妻| 精品国产乱码久久久久软件| 久久99国产精品久久99小说| 亚洲精品99久久久久中文字幕| 久久婷婷五月综合成人D啪| 久久狠狠一本精品综合网| 久久久久人妻一区精品| 色综合久久中文字幕综合网| 欧美国产成人久久精品| 成人综合久久精品色婷婷|