【发布时间】:2012-05-04 09:45:17
【问题描述】:
我正在尝试创建一个将地图作为模板参数的类。特别是它应该能够采用 std::map 和 boost::ptr_map。目前我正在尝试这个:
template <template<typename, typename> class MAP, typename KEYTYPE, typename DATATYPE>
class RestrictedMapBase
{
/* bunch of methods ... */
}
这个类被另外两个类继承,一个用于std::map,一个用于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 ... */
};
但在编译时出现以下错误:
RestrictedMap.h(166):错误 C3201:模板参数列表 类模板 'std::map' 与模板参数列表不匹配 对于模板参数 'MAP' RestrictedMap.h(183):见参考 类模板实例化 'STLUtils::RestrictedMap' 正在编译
RestrictedMap.h(186):错误 C3201:模板参数列表 类模板 'boost::ptr_map' 与模板参数不匹配 模板参数 'MAP' RestrictedMap.h(203) 的列表:参见 引用类模板实例化 'STLUtils::RestrictedPointerMap' 正在编译
谁能指出我做错了什么的正确方向?谢谢。
【问题讨论】: