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

            亚洲狠狠久久综合一区77777| 久久无码人妻一区二区三区 | 狠狠色丁香久久婷婷综| 色综合久久中文字幕无码| 久久99精品久久只有精品| 亚洲国产精品热久久| 亚洲七七久久精品中文国产| 亚洲AV日韩精品久久久久| 国产精品99久久久久久人| 很黄很污的网站久久mimi色| 人妻无码精品久久亚瑟影视| 久久精品国产福利国产秒| 亚洲国产日韩综合久久精品| 精品亚洲综合久久中文字幕| 合区精品久久久中文字幕一区| 色婷婷综合久久久久中文 | 久久国产一区二区| A级毛片无码久久精品免费| 久久国产精品成人免费| 国产成人久久精品一区二区三区 | 狠狠色丁香婷婷综合久久来来去| 亚洲色欲久久久久综合网| 伊人色综合久久| 久久亚洲国产成人精品性色| 日本久久中文字幕| 青青草原综合久久| 久久久精品国产sm调教网站| 亚洲级αV无码毛片久久精品| 久久艹国产| 久久国产视频网| 国产精品无码久久四虎| 精品久久8x国产免费观看| 伊人久久无码中文字幕| 久久人人爽人人爽人人片AV东京热 | 久久精品成人| 久久99精品久久久久久齐齐| 99久久国产综合精品网成人影院 | 99久久精品国产麻豆| 久久亚洲精品人成综合网| 午夜精品久久久久久中宇| 精品一二三区久久aaa片|