模板函数定义迭代器不识别的解决方法
来源:互联网 发布:我的淘宝是什么流量 编辑:程序博客网 时间:2024/06/10 09:13
模板函数如下:
template <typename T> //重载<<的模板函数ostream &operator<<(ostream &out, const list<T> &lst){ list<T>::const_iterator ref = lst.begin(); for( ; ref != lst.end(); ref++) out << *ref; return out;}
编译时报错如下:
error: need ‘typename’ before ‘list< T>::const_iterator’ because ‘list< T>’ is a dependent scope
原因:
在list< T>前面需要用typename限定一下,因为编译器不知道list< T>::const_iterator是代表一个类型还是list中的一个成员iterator。
解决方法:
list<T>::const_iterator ref = lst.begin();
改为
typename list<T>::const_iterator ref = lst.begin();
阅读全文
0 0
- 模板函数定义迭代器不识别的解决方法
- 模板类中定义std::list::iterator iter在Linux下不识别的解决方法。
- 模板类中定义 std::list::iterator iter在Linux下不识别的解决方法。
- 模板类中定义 std::list<T>::iterator iter编译器不识别的解决方法。
- 模板函数的定义问题
- 函数模板的定义和使用
- 模板类中友元函数的声明与定义
- 函数模板和类模板的定义和使用
- 定义函数模板
- 如何定义函数模板
- C++ 定义函数模板
- 定义函数模板
- 模板(函数模板和类模板基本类似,类模板的定义需要注意)
- 定义指向模板函数的函数指针类型
- 类模板函数分开定义
- 模板类中定义list<T>::iterator iter在g++下不识别的解决办法
- 模板类中定义list<T>::iterator iter在g++下不识别的解决办法
- C的宏定义实现模板函数——C的C++模板函数机制实现
- iOS 各种demo链接汇总~刷新(第三方控件)
- jenkins介绍部署及三种构建方式配置
- 数据量大时 导出失败,增加tomcat内存
- 【nginx】定时器的实现及定时事件的使用
- 2.1 最基础的“穷竭搜索”
- 模板函数定义迭代器不识别的解决方法
- 【头条】戴尔与环法携手,共同诠释前无止境
- Neo4j启动失败Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual.
- 数据库的存储过程
- android手机通讯录
- js 前端防xss攻击——百度UEditor解决方案
- Exception starting filter struts2 Unable to load configuration.包重复所致
- RIOT简介
- HttpURLConnection应用