【发布时间】:2013-11-27 23:44:40
【问题描述】:
我不熟悉 C++ 中的泛型函数。我有一个打印向量内部的模板函数。
template<class T>
void print(vector<T> v){
for(typename vector<T>::iterator it=v.begin(); it != v.end() ; it++)
cout << *it << endl;
}
我想写一个更通用的print() 来打印一个 STL 容器的内部。从现在开始,我该如何继续?
【问题讨论】:
-
使用模板参数作为迭代器类型。
标签: c++ templates stl generic-programming