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

            woaidongmao

            文章均收錄自他人博客,但不喜標題前加-[轉貼],因其丑陋,見諒!~
            隨筆 - 1469, 文章 - 0, 評論 - 661, 引用 - 0
            數據加載中……

            模版套模版

            1 模版類中有成員是模版:
            #include <iostream>
            #include
            <typeinfo>
            using namespace std;

            template
            <class T>
            class Outer
            {
            public:
              template
            <class R>
             
            class Inner
             
            {
             
            public:
               
            void f();
              }
            ;
            }
            ;

            template
            <class T> 
            template
            <class R>
            void Outer<T>::Inner<R>::f()
            {
              cout
            << "Outer == " << typeid(T).name() << endl;
              cout
            << "Inner == " << typeid(R).name() << endl;
              cout
            << "Full Inner == " << typeid(*this).name() << endl;
            }


            int main()
            {
              Outer
            <int>::Inner<bool> inner;
              inner.f();
            }
             ///:~

            //output:
            //Outer == int
            //Inner == bool
            //Full Inner == class Outer<int>::Inner<bool>
            //Press any key to continue . . .

            2 模版類的參數是模版:
            // A print function for standard C++ sequences
            #include <iostream>
            #include
            <list>
            #include
            <memory>
            #include
            <vector>
            #include
            <deque>
            using namespace std;

            template
            <class T, template<class U, class = allocator<U> >
                             
            class Seq>
            void printSeq(Seq<T>& seq)
            {
             
            for (typename Seq<T>::iterator b = seq.begin();
                   b
            != seq.end();)
                cout
            << *b++ << endl;
            }


            int main()
            {
             
            // Process a vector
              vector<int> v;
              v.push_back(
            1);
              v.push_back(
            2);
              printSeq(v);
             
            // Process a list
              list<int> lst;
              lst.push_back(
            3);
              lst.push_back(
            4);
              printSeq(lst);

             
            // Process a deque
              deque<int> d;
              d.push_back(
            5);
              d.push_back(
            6);
              printSeq(d);
            }
             ///:~

            注意:typename 通知編譯器被限定的標識符應該為類型,不同與typedef 是定義新的類型。

            posted on 2008-09-14 18:13 肥仔 閱讀(445) 評論(1)  編輯 收藏 引用 所屬分類: C++ 模板

            評論

            # re: 模版套模版[未登錄]  回復  更多評論   

            我的怎么不能通過

            E:\MAIN work\thinking in c++\TICPP-2nd-ed-Vol-two\code\C05\MemberClass.cpp(19) : error C2059: syntax error : ''template<''
            E:\MAIN work\thinking in c++\TICPP-2nd-ed-Vol-two\code\C05\MemberClass.cpp(19) : error C2065: 'R' : undeclared identifier
            E:\MAIN work\thinking in c++\TICPP-2nd-ed-Vol-two\code\C05\MemberClass.cpp(25) : error C2143: syntax error : missing ';' before '{'
            E:\MAIN work\thinking in c++\TICPP-2nd-ed-Vol-two\code\C05\MemberClass.cpp(25) : error C2447: missing function header (old-style formal list?)
            2012-01-02 23:13 | 小杰
            精品久久久久久久久午夜福利 | 日韩精品无码久久久久久| 久久婷婷色香五月综合激情 | 久久久青草久久久青草| 精品国产青草久久久久福利 | 国产一区二区精品久久岳| 久久久久一本毛久久久| 国产亚洲精品久久久久秋霞| 粉嫩小泬无遮挡久久久久久| 久久精品国产只有精品66| 亚洲国产精品狼友中文久久久| 色诱久久久久综合网ywww| 国内精品久久久久久久久电影网| 国产精品乱码久久久久久软件 | 亚洲精品97久久中文字幕无码| 日产精品久久久久久久| 久久99精品国产99久久6| 人人狠狠综合久久88成人| 久久久久国产日韩精品网站| 午夜精品久久久久久毛片| 久久精品国产精品亚洲下载 | 亚洲AV无码久久精品成人| 精品99久久aaa一级毛片| 久久久久高潮毛片免费全部播放| 久久五月精品中文字幕| 久久se精品一区精品二区| 久久夜色精品国产噜噜麻豆| 人妻无码αv中文字幕久久琪琪布| 国产精品99久久久久久董美香| 伊人久久大香线蕉av不变影院| 久久影视综合亚洲| 91久久精品无码一区二区毛片| 久久99国产精品久久99果冻传媒| 久久午夜无码鲁丝片秋霞| 亚洲精品美女久久久久99小说| 久久精品成人一区二区三区| 久久综合亚洲色HEZYO社区 | 午夜精品久久久久久99热| 精品伊人久久久| 狠狠色噜噜色狠狠狠综合久久| 久久影视国产亚洲|