template关键字的一个特殊用法
2012-10-15 22:18
218 查看
#include <iostream> struct T1 { T1() : value(0) { } const int value; }; struct T2 { template <int N> int value(int n) const { return(N + n); } }; template <typename T> int func1(const T & t) { /* same as: return((t.value < 3) > 5); */ return(t.value<3>(5)); } template <typename T> int func2(const T & t) { /* call member template function of T */ return(t. template value<3>(5)); } int main(int argc, char * argv[]) { T1 t1; T2 t2; std::cout << (t1.value<3>(5)) << std::endl; std::cout << (t2.value<3>(5)) << std::endl; std::cout << func1(t1) << std::endl; // std::cout << func1(t2) << std::endl; // error // std::cout << func2(t1) << std::endl; // error std::cout << func2(t2) << std::endl; return(0); }
调用模板参数的成员模板的方法:
obj.template mem_template_func<arg_type>(args);
相关文章推荐
- C#中的yield关键字的一个用法
- @使用一个用户创建目录--特殊用法@
- C# 关于out关键字的用法(一个方法返回多个值的问题)
- template 用法(简单点一下)+送一个逗比并查集
- Java中特殊关键字的用法及效果
- appcache的一个特殊用法
- 使用Template时 typename 关键字的用法
- JavaScript中圆括号()和方括号[]的一个特殊用法
- Session Cookie的一个特殊用法
- C 宏的一个特殊用法
- 发现了一个很高端的双层嵌套关键字用法
- C# 关于out关键字的用法(一个方法返回多个值的问题)
- c++模板中的 typename 和 template 关键字用法
- CPP Templates 之 template 关键字的用法技巧
- 关于结构体的一个特殊用法(总觉得遇到的问题就该记录一下哇)
- 在struts2 中 JSONArray.fromObject转化字符串的一个特殊用法,直接返回值
- CONNECT BY(ROWNUM|LEVEL) 特殊用法解释(试着解释)
- StringTemplate.net模板技术用法
- break的特殊用法(可以实现goto的功能);递归的基础
- linux Freebsd 特殊符号的用法