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

            久久乐国产综合亚洲精品| 亚洲午夜久久久久久噜噜噜| 国产精品久久影院| 青青草国产精品久久久久| 7国产欧美日韩综合天堂中文久久久久| 99久久中文字幕| 日产久久强奸免费的看| 国内精品久久久久久久久电影网 | 国产人久久人人人人爽| 色偷偷888欧美精品久久久| 香蕉99久久国产综合精品宅男自| 亚洲香蕉网久久综合影视| 亚洲嫩草影院久久精品| 久久受www免费人成_看片中文 | 漂亮人妻被黑人久久精品| 99久久国产热无码精品免费久久久久| 日本精品久久久久影院日本| 国产一级做a爰片久久毛片| 精品国产乱码久久久久软件| 久久艹国产| 免费国产99久久久香蕉| 精品久久久久久久久午夜福利| 久久久久这里只有精品 | 久久精品国产亚洲AV高清热| 久久国产精品无码网站| 精品久久久久久亚洲精品| 国产成人久久精品一区二区三区| 人人狠狠综合久久亚洲88| 久久久精品2019免费观看| 久久精品日日躁夜夜躁欧美| 精品无码久久久久久久久久| 久久亚洲国产午夜精品理论片| 国产人久久人人人人爽| 国产午夜免费高清久久影院| 亚洲色大成网站www久久九| 久久伊人五月丁香狠狠色| 伊人久久亚洲综合影院| 亚洲伊人久久综合影院| 无码人妻久久一区二区三区蜜桃 | 国产精品久久久久久久久软件| 久久伊人中文无码|