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

            青青草原精品99久久精品66| 国产亚洲精久久久久久无码| 国产精品99久久久久久猫咪| 久久国产精品免费| 一级女性全黄久久生活片免费 | 久久人人爽人人爽人人片AV高清| 18禁黄久久久AAA片| 久久国产精品无码一区二区三区 | 亚洲精品蜜桃久久久久久| 精品熟女少妇a∨免费久久| 国产精品美女久久久网AV| 亚洲午夜久久久| 久久精品国产91久久麻豆自制| 国产成人精品久久亚洲高清不卡 | 久久国产亚洲精品| 国产日韩久久免费影院| 亚洲精品无码久久一线| 久久91精品综合国产首页| 久久超乳爆乳中文字幕| 狠狠色丁香婷婷久久综合| 国产精品久久久天天影视香蕉| 色偷偷久久一区二区三区| 精品国产青草久久久久福利| 九九久久自然熟的香蕉图片| 久久精品极品盛宴观看| 久久精品国产一区二区三区不卡| 久久人人爽人人爽人人片av高请| 国产免费久久精品99久久| 国产∨亚洲V天堂无码久久久| 久久精品免费一区二区| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 精品国产91久久久久久久| 99精品国产99久久久久久97| 久久午夜夜伦鲁鲁片免费无码影视| 久久人人爽人人爽人人片AV麻豆 | 一本久久免费视频| 亚洲欧美另类日本久久国产真实乱对白| 亚洲国产成人久久精品影视 | 国产精品嫩草影院久久| 成人久久精品一区二区三区| 精品九九久久国内精品|