7
4

2 回答 2

16

Because allocator is 4th template parameter, whereas 3rd parameter is comparator like std::less? so std::map<int, int, std::less<int>, Allocator< std::pair<const int, int> > > should work.

Also I think you should add default ctor and copy ctor:

  Allocator() {}

  template<class Other>
  Allocator( const Allocator<Other>& _Right ) {}
于 2011-06-09T16:48:10.297 回答
1

In case if someone is looking for the generalized way:

template<class Key, class T,class Compare = std::less<Key>, class _Ax = Allocator<std::pair<const Key, T> >>
class Map : public std::map<Key, T, Compare, _Ax >
{
};

Then use it,

Map<int,char> myMap;
myMap.insert<std::pair<int,char>(1,'o');
于 2018-02-05T17:06:34.503 回答