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

            亚洲精品NV久久久久久久久久 | 91久久精品视频| 中文字幕久久亚洲一区| 久久影院久久香蕉国产线看观看| 日韩久久无码免费毛片软件| 蜜桃麻豆WWW久久囤产精品| 久久精品青青草原伊人| 久久国产成人精品麻豆| 亚洲国产成人久久综合一区77| 中文字幕久久波多野结衣av| 久久本道伊人久久| 中文字幕无码av激情不卡久久| 久久精品国产2020| 久久午夜福利电影| 99久久精品费精品国产一区二区| 婷婷久久综合九色综合绿巨人| 久久精品国产亚洲精品2020| 蜜臀久久99精品久久久久久| 亚洲AV无码成人网站久久精品大| 久久国产精品一区| 2020最新久久久视精品爱| 久久精品国产久精国产一老狼| 久久精品成人免费观看97| 国产V亚洲V天堂无码久久久| 亚洲精品NV久久久久久久久久| 91精品久久久久久无码| 久久国产精品一区二区| 波多野结衣中文字幕久久| 久久久久亚洲国产| 日本精品久久久久影院日本| 国产精品一区二区久久精品无码| 国内精品久久久久影院一蜜桃| 亚洲精品乱码久久久久久按摩 | 伊人色综合久久天天人守人婷| 99久久人妻无码精品系列蜜桃| 思思久久精品在热线热| 伊人久久五月天| 久久久精品国产免大香伊| 三级三级久久三级久久| 久久99久国产麻精品66| 中文字幕久久精品无码|