牵着老婆满街逛

严以律己,宽以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

模板类中使用iterator成员出错的解决办法

今天写一个模板类,出于的目的是要写的模板类原本是两个管理类,里面除了被管理的类不同之外其他全部相同,但是今后可能两者会被扩充,如果写成一个就不好的。
后来想想还是把它改写成为一个模板类才行。
在类当中有一个std::list的成员,我要定义一个访问器:
 std::list<T*>::iterator begin() {return list.begin();};


但是结果是出现类似如下的编译错误:
error: type `std::vector<T, std::allocator<_CharT>; >;' is not derived from type `Record<T>;'
error: ISO C++ forbids declaration of `iterator' with no type

后来查到了,原来要在之前加一个 typename
正确代码如下:
typename std::list<T*>::iterator iter;

posted on 2007-09-10 15:24 杨粼波 阅读(686) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理