c++有关模板函数问题

yuegui2 2008-11-05 02:32:56

#include<iostream>
#include<list>
using namespace std;
template <class T>
void ccount(list<T> mylist)
{
list<T>::iterator ite;
}

为什么第七行老是编译错误,没法编译....
...全文
92 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
e_sharp 2008-11-05
  • 打赏
  • 举报
回复
typename list<T>::iterator ite;
yshuise 2008-11-05
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ccdbeyond 的回复:]
#include <iostream>
#include <list>
using namespace std;
template <class T>
void ccount(list <T> mylist)
{
mylist::iterator ite;  //***************************
}

改成他即可!不过要加上main()函数啊!!!
[/Quote]
不对。
对于模板来说,编译器无法识别是一个类型的时候需要加typename
cnn_503 2008-11-05
  • 打赏
  • 举报
回复
学习了
ccdbeyond 2008-11-05
  • 打赏
  • 举报
回复
#include <iostream>
#include <list>
using namespace std;
template <class T>
void ccount(list <T> mylist)
{
mylist::iterator ite; //***************************
}

main(){}

即可
ccdbeyond 2008-11-05
  • 打赏
  • 举报
回复
#include<iostream>
#include<list>
using namespace std;
template <class T>
void ccount(list<T> mylist)
{
mylist::iterator ite; //***************************
}

改成他即可!不过要加上main()函数啊!!!
lann64 2008-11-05
  • 打赏
  • 举报
回复
typename list<T>::iterator ite;
清钟沁桐 2008-11-05
  • 打赏
  • 举报
回复
我使用VC6没有问题
#include<iostream>
#include<list>
using namespace std;

template <class T>
void ccount(list<T> mylist)
{
list<T>::iterator ite;
}


void main()
{
char aa[] = "vfdff@hotmail.com";// 这里的字符串 在常量区 const
char *str = "zhong"; // 这里的字符串 在常量区 const
}通过了编译
deng2000 2008-11-05
  • 打赏
  • 举报
回复
list<T>::iterator ite;
==>
typename list<T>::iterator ite;
yuegui2 2008-11-05
  • 打赏
  • 举报
回复
老是无法在外部函数体里面声明iterator,不知道是为什么、

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧