|
- #include <iostream>
- #include <list>
- using namespace std;
- template<typename T>
- void output(T &l)
- {
- for(T::const_iterator it = l.begin(); it != l.end(); ++it)
- cout << *it << endl;
- }
- int main()
- {
- int ints[] = {10, 9, 8, 7, 6, 3};
- list<int> lst(ints, ints + sizeof(ints)/sizeof(ints[0]));
- output(lst);
- return 0;
- }
复制代码
编译输出的结果为:
[root@localhost tmp]# g++ main.cpp
main.cpp: In function ‘void output(T&)’:
main.cpp:10: 错误:expected `;' before ‘it’
main.cpp:10: 错误:‘it’ 在此作用域中尚未声明
main.cpp: In function ‘void output(T&) [with T = std::list<int, std::allocator<int> >]’:
main.cpp:19: instantiated from here
main.cpp:10: 错误:依赖名 ‘T::const_iterator’ 被解析为非类型,但实例化却产生了一个类型
main.cpp:10: 附注:如果您想指定类型,请使用 ‘typename T::const_iterator’
请问该问题该如何解决???? |
|