I’m trying to make a class that takes a map as a template parameter. In particular it should be able to take std::map and boost::ptr_map. Currently I’m trying this:
template <template<typename, typename> class MAP, typename KEYTYPE, typename DATATYPE>
class RestrictedMapBase
{
/* bunch of methods ... */
}
This class is being inherited by two other classes, one for std::map and one for boost::ptr_map.
template <typename KEYTYPE, typename DATATYPE>
class RestrictedMap: public RestrictedMapBase<std::map, KEYTYPE, DATATYPE>
{
/* Bunch of methods ... */
};
template <typename KEYTYPE, typename DATATYPE>
class RestrictedPointerMap: public RestrictedMapBase<boost::ptr_map, KEYTYPE, DATATYPE>
{
/* Bunch of methods ... */
};
But on compilation I get these errors:
RestrictedMap.h(166) : error C3201: the template parameter list for
class template ‘std::map’ does not match the template parameter list
for template parameter ‘MAP’ RestrictedMap.h(183) : see reference
to class template instantiation
‘STLUtils::RestrictedMap’ being compiledRestrictedMap.h(186) : error C3201: the template parameter list for
class template ‘boost::ptr_map’ does not match the template parameter
list for template parameter ‘MAP’ RestrictedMap.h(203) : see
reference to class template instantiation
‘STLUtils::RestrictedPointerMap’ being compiled
Can anybody point me in the right direction of what I’m doing wrong? Thanks.
Class template
std::maphave 4 arguments:Thus it can not be pass via
template<typename, typename>just like you can not assign a pointer to a 3-argument function to a pointer to 2-argument function.The solution is to pass the exact type to use to
RestrictedMapBase:Your initial design also limits users of your class because they can not specify a compare function for keys (or a hash function if they want to use hash tables) and an allocator.