[问题]如何用STL中list<T>::iterator作FUNCTION参数
PS: 本人想写一个IO类,可以直接将STL中list container写人文件中
但是, 中间有错误, 如题...........请高手指点
____________________________________________________
File.h
这里只是一个测试类, 我把主要出错地方,写出来DEBUG
____________________________________________________
#ifndef _FILE_H_
#define _FILE_H_
#include <STRING>
#include <list>
#include <fstream>
using std::list;
class File
{
public:
File(){};
template<class T>
void Write(list<T>::iterator first, list<T>::iterator last); //ERROR, 不知道原因
};
#endif
_________________________________________
File.cpp
同上, 测试类, 只是ERROR部分
_________________________________________
#include "file.h"
template<class T>
void File::Write(list<T>::iterator first, list<T>::iterator last) //同样这一行出错
{
// 空FUNCTION也不能通过编译
}
___________________________________________
Compiling...
file.cpp
e:\my documents\program\test\file.h(18) : error C2653: 'list<`template-parameter257',class _STL::allocator<`template-parameter257'> >' : is not a class or namespace name
e:\my documents\program\test\file.h(18) : error C2061: syntax error : identifier 'iterator'
e:\my documents\program\test\file.cpp(4) : error C2653: 'list<`template-parameter257',class _STL::allocator<`template-parameter257'> >' : is not a class or namespace name
e:\my documents\program\test\file.cpp(4) : error C2061: syntax error : identifier 'iterator'
Error executing cl.exe.
Creating browse info file...
test.exe - 4 error(s), 0 warning(s)
____________________________________
PS: 请高手指点一下, 请原谅本人的国语, 还有本人的中文. 中文水平较低.
问题点数:100、回复次数:5Top
1 楼csu_yzb(白杨)回复于 2006-03-11 09:16:45 得分 5
貌似将 using std::list;
改为 using namespace std;
就没有问题了Top
2 楼fangrk(加把油,伙计!)回复于 2006-03-11 09:45:23 得分 80
#include <list>
using std::list;
using namespace std;
class MyFile
{
public:
MyFile(){};
template<class T>
void Write(typename list<T>::iterator first,typename list<T>::iterator last)
{
//...
}
};
int main()
{
MyFile mf;
}
D:\Study\Test>cl /GX b.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
b.cpp
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
/out:b.exe
b.obj
D:\Study\Test>
受限于模板,要使用typenameTop
3 楼fangrk(加把油,伙计!)回复于 2006-03-11 09:46:31 得分 5
using namespace std;去掉好了Top
4 楼defyer007(深入浅出)回复于 2006-03-11 10:05:13 得分 5
VC6 是不是对标准类库的支持不太好啊?Top
5 楼csu_yzb(白杨)回复于 2006-03-11 10:43:12 得分 5
to fangrk:
using namespace std;去掉好了
--------------
能行吗?
Top




