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

            健康,快樂,勇敢的寧帥!!

            努力、努力、再努力! 沒有什么能阻止我對知識的渴望。

             

            "C++Templates The Complete Guide"讀書筆記----Chapter 4

            Chapter 4 Nontype Template Parameters
            1. Templates can have template parameters that are values rather than types
            With this class, user of the stack could specify this size of the array as the maximum size needed for stack elements
            template?<typename?T,?int?MAXSIZE>
            class?Stack?{
            ??
            private:
            ????T?elems[MAXSIZE];????????
            //?elements
            ????int?numElems;????????????//?current?number?of?elements

            ??
            public:
            ????Stack();??????????????????
            //?constructor
            ????void?push(T?const&);??????//?push?element
            ????void?pop();???????????????//?pop?element
            ????T?top()?const;????????????//?return?top?element
            ????bool?empty()?const?{??????//?return?whether?the?stack?is?empty
            ????????return?numElems?==?0;
            ????}

            ????
            bool?full()?const?{???????//?return?whether?the?stack?is?full
            ????????return?numElems?==?MAXSIZE;
            ????}

            }
            ;

            //?constructor
            template?<typename?T,?int?MAXSIZE>
            Stack
            <T,MAXSIZE>::Stack?()
            ??:?numElems(
            0)???????????????//?start?with?no?elements
            {
            ????
            //?nothing?else?to?do
            }


            template?
            <typename?T,?int?MAXSIZE>
            void?Stack<T,MAXSIZE>::push?(T?const&?elem)
            {
            ????
            if?(numElems?==?MAXSIZE)?{
            ????????
            throw?std::out_of_range("Stack<>::push():?stack?is?full");
            ????}

            ????elems[numElems]?
            =?elem;???//?append?element
            ????++numElems;???????????????//?increment?number?of?elements
            }


            template
            <typename?T,?int?MAXSIZE>
            void?Stack<T,MAXSIZE>::pop?()
            {
            ????
            if?(numElems?<=?0)?{
            ????????
            throw?std::out_of_range("Stack<>::pop():?empty?stack");
            ????}

            ????
            --numElems;???????????????//?decrement?number?of?elements
            }


            template?
            <typename?T,?int?MAXSIZE>
            T?Stack
            <T,MAXSIZE>::top?()?const
            {
            ????
            if?(numElems?<=?0)?{
            ????????
            throw?std::out_of_range("Stack<>::top():?empty?stack");
            ????}

            ????
            return?elems[numElems-1];??//?return?last?element
            }
            2. You can also define nontype parameters for function templates.
            template?<typename?T,?int?VAL>
            T?addValue?(T?
            const&?x)
            {
            ????
            return?x?+?VAL;
            }
            However, according to the current standard, sets of overloaded functions cannot? be used for template parameter deduction. Thus, you have to cast to the exact type of the function template argument:
            std::transform(source.begin(),source.end(),//?start?and?end?of?source
            ???????????????dest.begin(),//?start?of?destination
            ???????????????(int(*)(int?const&))addValue<int,5>);//operation
            There is a proposal for the standard to fix this behavior so that the cast isn't necessary.
            2. You cannot use floating-point numbers, class-type objects, and objects with internal linkage(such as string literals) as arguments for nontype template parameters

            posted on 2006-11-26 19:50 ningfangli 閱讀(139) 評論(0)  編輯 收藏 引用

            導航

            統(tǒng)計

            公告

            Dict.CN 在線詞典, 英語學習, 在線翻譯

            常用鏈接

            留言簿(4)

            隨筆檔案

            文章分類

            文章檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产亚洲av高清漫画| 久久―日本道色综合久久| 国产亚洲色婷婷久久99精品91| 久久精品亚洲乱码伦伦中文| 欧美久久亚洲精品| 热re99久久6国产精品免费| 国产成人久久激情91| 精品久久国产一区二区三区香蕉| 久久国产精品无| 久久美女人爽女人爽| 伊人久久无码精品中文字幕| www性久久久com| 亚洲午夜久久久| 99久久国产综合精品五月天喷水 | 日韩欧美亚洲综合久久影院Ds| 久久人妻少妇嫩草AV蜜桃| 2021少妇久久久久久久久久| 亚洲?V乱码久久精品蜜桃 | 久久九九全国免费| 一级女性全黄久久生活片免费 | 亚洲国产视频久久| 大美女久久久久久j久久| 久久综合亚洲欧美成人| 久久99热这里只频精品6| 久久久久香蕉视频| 伊人色综合久久| 欧美亚洲另类久久综合| 狠狠色丁香久久综合婷婷| 久久久久亚洲精品无码蜜桃| 久久久久亚洲AV无码专区首JN | 少妇久久久久久被弄到高潮| 亚洲午夜精品久久久久久人妖| 国产精品久久久久久久久| 久久AV高清无码| 99久久久国产精品免费无卡顿| 久久精品九九亚洲精品| 久久精品午夜一区二区福利| 久久青青草原精品国产| 韩国无遮挡三级久久| 91麻豆精品国产91久久久久久| 日本久久久久久中文字幕|