effective C++条款四十二解读
来源:互联网 发布:linux 修改时区 cst 编辑:程序博客网 时间:2024/06/05 04:52
了解typename的双重意义
1.template <class T>与template <typename T>没有区别。
typename 的另一种用法,我们以一个代码来解释:
template<typename C>void print2nd(const C&container){if(container.size()>2){C::const_iterator iter(container.begin());++iter;int value=*iter;std::cout<<value;}}C::const_iterator 的名称依赖于模板参数C,是从属于C的名称,同时带了::符号是一个从属嵌套名称,需要在前面加上typename
template<typename C>void print2nd(const C&container){if(container.size()>2){typename C::const_iterator iter(container.begin());++iter;int value=*iter;std::cout<<value;}}这样才能通过编译,不然C::const_iterator 完全可能是一个静态变量。
由于 C::const_iter太长我们经常会有这种用法 typedef typename C::const_iter const_iter.
另外注意不要把typename放在基类列表以及成员初始列之中。
阅读全文
0 0
- effective C++条款四十二解读
- Effective C++ 条款二解读
- effective C++ 条款三 解读
- effective c++ 条款4解读
- effective C++条款五解读
- effective C++ 条款六解读
- effective C++ 条款八解读
- effective C++ 条款九解读
- effective C++ 条款十解读
- effective C++ 条款十一解读
- effective C++ 条款十二解读
- effective C++ 条款十三解读
- effective c++ 条款十四解读
- effective C++条款十五解读
- effective C++ 条款十六解读
- effective C++ 条款十七解读
- effective C++ 条款十八解读
- effective C++条款十九解读
- 搭建测试网站
- Mockito 学习篇(三)
- SpringMVC 通配符的匹配很全面, 但无法找到元素 'mvc:default-servlet-handler' 的声明。
- IntelliJ IDEA快捷键
- 抓包简单使用介绍
- effective C++条款四十二解读
- Git详解之九 Git内部原理
- Linux中rz和sz命令用法
- kafka管理器kafka-manager部署安装
- Java8源码-Map总结
- 把数组排成最小的数
- ubuntu 修改默认root密码
- ionic2 遇到的一些小问题
- android UiAutomator如何根据颜色判断控件的状态