关于模版具现的问题

l_clove 2007-11-22 06:22:21
#include <iostream>
#include <list>
using namespace std;

template <typename T>
int test(T val)
{
list <T *>::iterator _it;

return 0;
}

int main()
{
int i;
test(i);
}

在list <T *>::iterator _it;这个地方,GCC会报错:
STL.cpp: In function `int test(T)':
STL.cpp:8: error: expected `;' before "_it"
STL.cpp: In function `int test(T) [with T = int]':
STL.cpp:16: instantiated from here
STL.cpp:8: error: dependent-name ` std::list<T*,std::allocator<T*> >::iterator' is parsed as a non-type, but instantiation yields a type
STL.cpp:8: note: say `typename std::list<T*,std::allocator<T*> >::iterator' if a type is meant

bcc32则不会,为何?是否是GCC对于嵌套的模版具现有不同的实现?
...全文
105 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
l_clove 2007-11-23
  • 打赏
  • 举报
回复
Thx,解决,结帖!
yutaooo 2007-11-22
  • 打赏
  • 举报
回复
typename 啊!!!


#include <iostream>
#include <list>

template<typename T>
int test(T val) {
typename std::list<T*>::iterator it_;
return 0;
}

int main() {
int i;
test(i);
return 0;
}
l_clove 2007-11-22
  • 打赏
  • 举报
回复
自己先顶一下,程序是从以前的工程移植的,都是正常使用。

65,184

社区成员

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

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