• <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
            數(shù)據(jù)加載中……

            模版套模版

            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 模版類的參數(shù)是模版:
            // 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 肥仔 閱讀(451) 評論(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 | 小杰
            97久久精品人人做人人爽| 亚洲精品综合久久| 久久婷婷五月综合国产尤物app| 久久精品国产福利国产琪琪| 精品国产青草久久久久福利| 久久天天躁狠狠躁夜夜躁2O2O| A狠狠久久蜜臀婷色中文网| 亚洲午夜精品久久久久久人妖| 亚洲精品无码久久久久去q| 日本加勒比久久精品| 久久免费线看线看| 久久精品国产亚洲麻豆| 久久男人Av资源网站无码软件| 97久久国产综合精品女不卡| 久久久久九国产精品| 久久亚洲2019中文字幕| 国产精品激情综合久久| 国产成人精品久久亚洲| 久久久久久国产精品美女 | 狠狠色综合网站久久久久久久高清| www.久久热.com| 久久国产精品99精品国产987| 99久久综合狠狠综合久久止| 国产99久久精品一区二区| 久久精品成人免费网站| 久久亚洲国产午夜精品理论片| 国产成人精品久久| 精品熟女少妇aⅴ免费久久| 色99久久久久高潮综合影院| 久久精品视频一| 看久久久久久a级毛片| 爱做久久久久久| 国内精品伊人久久久久妇| 国产午夜精品久久久久免费视| 香蕉aa三级久久毛片| 国产69精品久久久久9999APGF | 久久九九全国免费| 久久天天日天天操综合伊人av| 久久亚洲精品成人av无码网站| 97久久精品人人澡人人爽| 色8激情欧美成人久久综合电|