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

            洗塵齋

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

            常用鏈接

            統計

            最新評論

            explicit關鍵字用法

            explicit關鍵字用于取消構造函數的隱式轉換,對有多個參數的構造函數使用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 芥之舟 閱讀(2477) 評論(0)  編輯 收藏 引用 所屬分類: C/C++

            久久亚洲国产成人影院网站| 囯产精品久久久久久久久蜜桃| 久久久久久久97| 国内精品久久久久影院一蜜桃| 久久精品国产福利国产秒| 久久电影网2021| 久久精品极品盛宴观看| 狠狠色丁香久久婷婷综合五月 | 久久99热只有频精品8| 99国内精品久久久久久久| 久久精品国产2020| 久久电影网一区| 香蕉久久av一区二区三区 | 丁香久久婷婷国产午夜视频| 亚洲国产日韩欧美久久| 久久精品国产亚洲欧美| 一本久久a久久精品vr综合| 精品国产综合区久久久久久 | 91久久精品视频| 无码国内精品久久人妻蜜桃| 久久五月精品中文字幕| 嫩草影院久久99| 国内精品伊人久久久久av一坑 | 色综合久久夜色精品国产| 国产亚洲精品自在久久| 狠狠综合久久综合88亚洲| 精品久久久久国产免费| 久久久久夜夜夜精品国产| 色婷婷综合久久久久中文| 精品国产青草久久久久福利| 亚洲国产成人久久一区久久| 久久精品国产清自在天天线| 青青青伊人色综合久久| 久久婷婷久久一区二区三区| 国内精品久久久久伊人av| 久久久老熟女一区二区三区| 久久人爽人人爽人人片AV| 亚洲午夜久久久久久久久久| 亚洲熟妇无码另类久久久| 国产成人无码精品久久久性色| 久久亚洲熟女cc98cm|