我有一个类看起来像这样:C++模板类
#include <vector>
#include "record.h"
#include "sortcalls.h"
template<
typename T,
template<typename , typename Allocator = std::allocator<T> > class Cont = std::vector>
class Sort: public SortCall {
此代码工作,我打电话像这样从其他类:
Comparator c; // comparison functor
Sort< Record, std::vector > s(c);
现在我希望能够将容器切换到另一个容器,比如列表。 所以我认为typedef会很整齐。它应该是这样的
typedef std::vector<Record> container; // Default record container
template<
typename T,
template< typename, typename container > // ???
class Sort: public SortCall {
我不确定我是否理解;你没有在任何地方使用'排序'。另外,'_Alloc'保留给编译器;你应该改变它为'Allocator'或者其他东西。 – GManNickG 2010-02-10 21:54:28
我不确定我明白为什么模板参数必须这么复杂。为什么不用'template class Sort ...'用'Sort s''? –
UncleBens
2010-02-10 22:05:06
@GMan thx。改变了它。 – mre 2010-02-10 22:06:49