摘要:
模板提要:模板的形参关键字,在c++前必须加上前缀class,为了区别关键字class,也可以用typename来替代。类模板的定义形式为:类模板名对象名;函数模板,后面可以直接调用,像平常函数一样。获取变长模板的长度:sizeof...(Args)#includetemplatestruct count{ static const int value = 1 + count::value; static void f(){printf("%d\n",sizeof...(Args))};};templatestruct count{ static const int val 阅读全文
摘要:
C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用。 const_cast,字面上理解就是去const属性。 static_cast,命名上理解是静态类型转换。如int转换成char。 dynamic_cast,命名上理解是动态类型转换。如子类和父类之间的多态类型转换。 reinterpreter_cast,仅仅重新解释类型,但没有进行二进制的转换。 4种类型转换的格式,如: TYPE B = static_cast(a)const_cast 去掉类型的const或volatile属性。 struct SA { int i; }; const SA ... 阅读全文