我有这个模板,我将输出操作符声明为朋友:
template <typename T, template <typename ELEM, typename ALLOC=std::allocator<ELEM> > class Cont=std::vector>
class VehiclesContainer {
public:
VehiclesContainer(std::initializer_list<T> l):container(l){};
virtual ~VehiclesContainer(){};
template
<typename U, template <typename ELEM2, typename ALLOC=std::allocator<ELEM2> > class Cont2>
friend std::ostream& operator<<(std::ostream& out, const VehiclesContainer<U,Cont2>& obj);
private:
Cont<T> container;
};
这是朋友的宣言:
template
<typename T,template <typename ELEM,typename ALOC=std::allocator<ELEM> > class Cont>
std::ostream& operator<<(std::ostream& out,const VehiclesContainer<T,Cont>& obj){
for(auto it=obj.container.begin(); it!=obj.container.end(); ++it)
out << *it << " ";
return out;
}
以前的作品,但是当我尝试声明typename Cont<T>::iterator it;
而不是使用auto
关键字时,它不起作用。任何想法如何在不使用auto
关键字的情况下声明迭代器?这不是那么重要,但我很好奇如何做到这一点。