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

            編譯器何時為你產生默認構造函數

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

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

            国产成人AV综合久久| 亚洲欧美一级久久精品| 国内精品久久久久久99| 亚洲国产精品婷婷久久| 一本久久a久久精品综合香蕉| 97精品依人久久久大香线蕉97 | 少妇久久久久久久久久| 久久久久人妻一区二区三区vr| 久久久久久久尹人综合网亚洲| 亚洲精品国产自在久久| 久久99热国产这有精品| 性色欲网站人妻丰满中文久久不卡| 色综合久久88色综合天天| 中文字幕无码精品亚洲资源网久久| 国产精品美女久久久免费 | 99国产精品久久| 午夜人妻久久久久久久久| 久久久久亚洲AV成人网人人软件| 久久久久亚洲精品天堂| 国产精品久久久久蜜芽| 亚洲美日韩Av中文字幕无码久久久妻妇 | 亚洲αv久久久噜噜噜噜噜| 欧美粉嫩小泬久久久久久久 | 99久久人妻无码精品系列| 久久婷婷五月综合成人D啪| 欧洲性大片xxxxx久久久| 精品久久久久久无码国产| 国产精品九九九久久九九| 亚洲国产精品无码久久SM| 久久久精品人妻一区二区三区蜜桃 | AV无码久久久久不卡网站下载 | 久久人人爽人人爽人人片AV麻豆 | 久久久久久久女国产乱让韩| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 777米奇久久最新地址| 99久久免费国产特黄| 人妻无码αv中文字幕久久| 久久夜色精品国产噜噜噜亚洲AV| 一本色道久久88精品综合| 麻豆亚洲AV永久无码精品久久| 久久久久久久久无码精品亚洲日韩|