• <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)計(jì)

            最新評(píng)論

            explicit關(guān)鍵字用法

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


            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 芥之舟 閱讀(2476) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C/C++

            久久精品国产99国产精品| 久久99精品久久久久久| 亚洲国产精品狼友中文久久久| 精品国产一区二区三区久久蜜臀| 久久久久国产成人精品亚洲午夜| 亚洲美日韩Av中文字幕无码久久久妻妇| 人人妻久久人人澡人人爽人人精品| 99久久这里只精品国产免费| 久久国产色AV免费看| 久久久久噜噜噜亚洲熟女综合| 777午夜精品久久av蜜臀| 久久精品国产精品国产精品污| 亚洲精品成人久久久| 久久国产亚洲高清观看| 久久久这里有精品| 亚洲国产成人久久精品动漫| 中文精品久久久久人妻不卡| 精品久久久久久无码国产| 久久精品国产亚洲av水果派| 青青草原综合久久大伊人| 国产成人精品久久| 2021少妇久久久久久久久久| 久久无码人妻一区二区三区午夜 | 国产日产久久高清欧美一区| 亚洲精品tv久久久久久久久久| 久久精品国产半推半就| 久久香蕉超碰97国产精品| 日本五月天婷久久网站| 深夜久久AAAAA级毛片免费看| 丰满少妇人妻久久久久久4| 久久精品国产亚洲av影院| 无码AV波多野结衣久久| 久久久久久久波多野结衣高潮| 久久精品国产亚洲AV不卡| 色综合色天天久久婷婷基地| 久久久久一区二区三区| 久久中文娱乐网| 久久综合狠狠色综合伊人| 99久久成人18免费网站| 久久国产香蕉视频| 无码人妻久久一区二区三区蜜桃|