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

            洗塵齋

            三懸明鏡垂鴻韻,九撩清泉洗塵心

            常用鏈接

            統(tǒng)計

            最新評論

            explicit關(guān)鍵字用法

            explicit關(guān)鍵字用于取消構(gòu)造函數(shù)的隱式轉(zhuǎn)換,對有多個參數(shù)的構(gòu)造函數(shù)使用explicit是個語法錯誤。


            In C++ it is possible to declare constructors for a class, taking a single parameter, and use those constructors for doing type conversion. For example:

            class?A?{
            public:
            ??????? A(
            int);
            };

            void?f(A)?{}
            void?g()
            {
            ???????? A?a1?
            =?37;
            ???????? A?a2?
            =?A(47);
            ???????? A?a3(
            57);
            ???????? a1?
            =?67;
            ???????? f(
            77);
            }

            A declaration like:
            ?A a1 = 37;
            says to call the A(int) constructor to create an A object from the integer value. Such a constructor is called a "converting constructor".

            However, this type of implicit conversion can be confusing, and there is a way of disabling it, using a new keyword "explicit" in the constructor declaration:

            class?A?{
            public:
            ???????
            explicit?A(int);
            };

            void?f(A)?{}
            void?g()
            {
            ????????? A?a1?
            =?37;??????//?illegal
            ????????? A?a2?=?A(47);???//?OK
            ????????? A?a3(57);???????//?OK
            ????????? a1?=?67;????????//?illegal
            ????????? f(77);??????????//?illegal
            }


            Using the explicit keyword, a constructor is declared to be
            "nonconverting", and explicit constructor syntax is required:

            class?A?{
            public:
            ????????
            explicit?A(int);
            ????????};

            void?f(A)?{}

            void?g()
            {
            ????????A?a1?
            =?A(37);
            ????????A?a2?
            =?A(47);
            ????????A?a3(
            57);
            ????????a1?
            =?A(67);
            ????????f(A(
            77));
            }


            Note that an expression such as:

                    A(47)

            is closely related to function-style casts supported by C++. For example:

                    double d = 12.34;

            int i = int(d);

            posted on 2006-04-19 21:11 芥之舟 閱讀(2486) 評論(0)  編輯 收藏 引用 所屬分類: C/C++

            国产69精品久久久久99| 久久成人永久免费播放| 亚洲综合精品香蕉久久网97 | 伊人久久大香线蕉综合5g| 亚洲AV伊人久久青青草原| 麻豆一区二区99久久久久| 国产亚洲精久久久久久无码AV| 久久久久香蕉视频| 久久99免费视频| 97精品依人久久久大香线蕉97 | 青青国产成人久久91网| 色综合久久久久综合体桃花网| 伊色综合久久之综合久久| 国产成人香蕉久久久久| 日本人妻丰满熟妇久久久久久| 国产成人久久精品二区三区| 午夜人妻久久久久久久久| 中文精品99久久国产 | 亚洲色大成网站WWW久久九九| 色综合久久久久| 精品国产VA久久久久久久冰| 亚洲AV无码成人网站久久精品大| 久久精品亚洲欧美日韩久久| 久久99久久99小草精品免视看| 性高湖久久久久久久久| 久久亚洲AV成人无码| 99精品久久精品一区二区| 久久久久亚洲国产| 欧美亚洲另类久久综合婷婷| 久久国产美女免费观看精品 | 精品久久久噜噜噜久久久 | 久久91精品国产91久久户| 99久久人妻无码精品系列| 久久久久AV综合网成人| 久久精品国产网红主播| 久久棈精品久久久久久噜噜| 久久精品亚洲精品国产色婷| 久久99国产精品久久99| 久久青青草原精品影院| 精品久久久久久久久久中文字幕 | 久久91精品国产91久久小草|