c ++自定义容器编译错误

时间:2014-02-27 05:06:14

标签: c++ templates

我正在尝试将容器写为

 template <typename T, typename A = std::allocator<T> >    
 class circular_dlist{
     ....
     public:

     class iterator{ 
       ....
     };

     void insert(T& val);
 };

在我将insert()方法定义为:

时的.cpp文件中
template <typename T, typename A = std::allocator<T> > 
void circular_dlist<T, A>::insert(T& val){
}

我收到以下错误:

error: default template arguments may not be used in function templates without -std=c++11 or -std=gnu++11

如果我不使用c ++ 11,在这种情况下定义类定义之外的函数的正确语法是什么?

1 个答案:

答案 0 :(得分:0)

简单地写

template <typename T, typename A> 
void circular_dlist<T, A>::insert(T& val){
}