我想编写类 Stack 的两个不同实现。
(1)
template<typename element_type, typename container_type = std::vector<element_type> >
class Stack{//...
};
(2)
template<typename element_type, size_t container_size>
class Stack{
};
如果我在一个文件中定义这两个实现,我会得到编译器错误。是否可以将它们都放在同一个文件中?
//compiler errors:
Stack.hpp:119:46: error: declaration of template ‘template<class element_type, long unsigned int container_size> int containers::Stack()’
Stack.hpp:25:9: error: conflicts with previous declaration ‘template<class element_type, class container_type> class containers::Stack’
Stack.hpp:25:9: error: previous non-function declaration ‘template<class element_type, class container_type> class containers::Stack’
Stack.hpp:119:46: error: conflicts with function declaration ‘template<class element_type, long unsigned int container_size> int containers::Stack()’