2011年3月16日

编译期断言

摘要: 书中列出三种编译期断言的实现方式,一一列出:CompileTimeAssertion.h //第一个版本使用不能建立空数组的性质#define STATIC_CHECK1(expr) \{\ char unnamed[(expr) ? 1 : 0];\}//第二个版本使用模板的非类形参,使用为定义类是违法的template<bool> struct CompileTimeError;//声明一个模板template<> struct CompileTimeError<true>{};//仅仅对模板参数为true的特化实现#define STATIC_CHEC 阅读全文

posted @ 2011-03-16 23:30 Observer 阅读(669) 评论(0) 推荐(0) 编辑

template template

摘要: #include<list>#include<vector>#include<iostream>using namespace std;/*如果有一个需求是在自定义类中使用某种类型(T)元素,固定容器(vecter)*/template<class T>class ClassA{public: vector<T> vecT;};//如果需求变成在自定义类中使用固定类型(int)元素,不同容器呢?template<class SpecificContainer>class ClassB{public: SpecificCon 阅读全文

posted @ 2011-03-16 22:48 Observer 阅读(342) 评论(0) 推荐(0) 编辑

导航