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

            色婷婷噜噜久久国产精品12p| 国产成人无码精品久久久免费| 久久久久久久国产免费看| 国产精品久久久久久久午夜片| 免费一级欧美大片久久网| 久久久久99精品成人片试看 | 久久天堂电影网| 久久久久成人精品无码| 久久综合给合久久狠狠狠97色69 | 久久久久18| 亚洲精品无码久久一线| 中文字幕久久欲求不满| 久久无码高潮喷水| 香蕉久久一区二区不卡无毒影院 | 久久免费香蕉视频| 亚洲AV日韩AV永久无码久久| 91精品国产91热久久久久福利| 久久婷婷五月综合国产尤物app | 国产精品久久久久久久久免费| 久久久久久国产a免费观看不卡| 久久久SS麻豆欧美国产日韩| 久久精品夜色噜噜亚洲A∨| 无码AV中文字幕久久专区| 久久国产美女免费观看精品| 国产精品一久久香蕉国产线看观看| 久久久受www免费人成| 久久综合中文字幕| 精品久久777| 精品999久久久久久中文字幕| 久久久久亚洲AV无码麻豆| 久久人做人爽一区二区三区| 激情久久久久久久久久| 欧美亚洲国产精品久久蜜芽| 久久久久亚洲AV无码麻豆| 日产精品99久久久久久| 亚洲国产精品无码久久久秋霞2| 国产欧美久久久精品影院| 亚洲欧洲精品成人久久奇米网| 久久久久亚洲AV成人网人人网站| 国产成人精品久久综合| 国产成人精品久久亚洲|