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

            久久国产成人精品麻豆| 久久午夜电影网| 久久久久久久精品妇女99| 中文字幕乱码久久午夜| 国产精品久久亚洲不卡动漫| 亚洲狠狠久久综合一区77777| 久久久99精品一区二区| 久久久久亚洲精品日久生情 | 久久99国产综合精品| 亚洲国产精品久久66| 久久精品日日躁夜夜躁欧美 | 久久99精品久久久久久野外| 无遮挡粉嫩小泬久久久久久久 | 香港aa三级久久三级| 伊人色综合久久天天网| 日本精品久久久久中文字幕| 7777精品伊人久久久大香线蕉| 久久91精品久久91综合| 国色天香久久久久久久小说| 久久精品无码av| 国产精品天天影视久久综合网| 人妻无码αv中文字幕久久琪琪布| 91久久精一区二区三区大全| 久久婷婷国产剧情内射白浆| 久久无码一区二区三区少妇| 久久电影网一区| 国内精品久久久久影院免费| 色狠狠久久AV五月综合| 午夜精品久久久久久影视777| 国产精品成人精品久久久| 久久国产乱子伦免费精品| 国产成人精品综合久久久久| 久久久久久久亚洲精品 | 久久精品一本到99热免费| 亚洲а∨天堂久久精品9966| 久久久久人妻精品一区三寸蜜桃| 久久精品中文字幕久久| 久久精品成人国产午夜| 国内精品人妻无码久久久影院 | 久久噜噜久久久精品66| 狠狠色丁香婷婷综合久久来来去|