我想在某个模板函数中迭代一个容器。如果容器是双端队列但它存储的类型是未知的,我试过:
template <typename T>
void PrintDeque(deque<T> d)
{
deque<T>::iterator it; //error here
for(it=d.begin();it!=d.end();it++)
cout<<*it<<" ";
cout<<endl;
}
或者,如果我对未知容器尝试此操作:
template <typename T>
void PrintDeque(T d)
{
T::iterator it; //error here
for(it=d.begin();it!=d.end();it++)
cout<<*it<<" ";
cout<<endl;
}
两者都给出编译错误。如何在模板函数中创建一个迭代器,以便我可以迭代容器?