Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板参数中容器迭代器的显式声明_C++_Templates_C++11 - Fatal编程技术网

C++ 模板参数中容器迭代器的显式声明

C++ 模板参数中容器迭代器的显式声明,c++,templates,c++11,C++,Templates,C++11,我有一个模板,其中我将输出操作符声明为朋友: template <typename T, template <typename ELEM, typename ALLOC=std::allocator<ELEM> > class Cont=std::vector> class VehiclesContainer { public: VehiclesContainer(std::initializer_list<T> l):containe

我有一个模板,其中我将输出操作符声明为朋友:

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;
};
模板
二级车辆及货柜{
公众:
VehicleContainer(std::initializer_list l):容器(l){};
virtual~VehiclesContainer(){};
模板

friend std::ostream&operator您需要使用
常量迭代器
,参数
obj
常量
@dyp您是对的,谢谢。
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;
}