iterator作为返回值示例

来源:百度知道 编辑:UC知道 时间:2024/06/08 10:04:39
这个老编译不通 iterator Listing:: end()

提示信息:error C2955: 'iterator' : use of class template requires template argument list

求个用iterator作为返回值的示例,谢!

错误原因:使用模板时未指明模板类型参数表

--------------------

比如要返回一个int的iterator,要这样写:

iterator<int> test() // 普通函数
{
……
}

------

如果在类中定义的话,要这样写:

template <class Type> Listing {
……
iterator<Type> Listing:: end(); // 类成员
……
};