C++爱好者

C++技术交流

常用链接

统计

最新评论

C++练习一自动匹配模版参数

 1#include <iostream>
 2#include <cstdio>
 3using namespace std;
 4namespace boost
 5{
 6    template <bool v>
 7    class s_bool
 8    {
 9    public:
10        explicit s_bool(bool isset)
11        {
12            cout <<isset<<endl;
13        }

14
16    }
;
17    typedef s_bool<true> b_true;
18    typedef s_bool<false> b_false;
19    template <typename T1,bool T2>
20    class NiftyContainer
21    {
22    private:
23        void DoSomeTing(T1 *pObj,b_true b)
24        {
25            T1 *plObj=new T1(*pObj);
26            cout <<plObj<<" true "<<&b<<endl;
27        }

28        void DoSomeTing(T1 *pObj,b_false b)
29        {
30            T1 *plObj=new T1(*pObj);
31            cout <<plObj<<" false "<<&b<<endl;
32        }

33    public:
34        void DoSomeTing(T1 *pObj)
35        {
36            DoSomeTing(pObj,s_bool<T2>(T2));
37        }

38    }
;
39    class Test
40    {
41    public:
42        Test()
43        {
44            cout <<"Test::Test"<<endl;
45        }
;
46    }
;
47}
;
48using namespace boost;
49int main()
50{
51    NiftyContainer<Test,false> pNifty;
52    Test *T=new Test;
53    pNifty.DoSomeTing(T);
54    getchar();
55    return 0;
56}

57

posted on 2012-03-09 00:02 混蛋 阅读(227) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理