如何创建boost::unordereded_map的子类
How do I create a subclass of boost::unordered_map?
我正在尝试子类化boost::unordered_map(这样我就可以捕获异常,而不会让异常捕获逻辑扰乱我的程序)。我已经成功地包装了boost::unordered_map,但我想尝试创建一个子类。
无论如何,我在确定正确的子类语法时遇到了问题。
以下不起作用:
template<typename Key, typename Mapped, typename Hash = boost::hash<Key>,
typename Pred = std::equal_to<Key>,
typename Alloc = std::allocator<std::pair<Key const, Mapped>> >
class unordered_map : public boost::unordered_map<typename Key, typename Mapped, typename Hash = boost::hash<Key>,
typename Pred = std::equal_to<Key>,
typename Alloc = std::allocator<std::pair<Key const, Mapped>> >
{
};
#include <boost/unordered_map.hpp>
template<typename Key, typename Mapped, typename Hash = boost::hash<Key>,
typename Pred = std::equal_to<Key>,
typename Alloc = std::allocator<std::pair<Key const, Mapped> > >
class my_unordered_map : public boost::unordered_map<Key, Mapped, Hash,Pred,Alloc>
{
};
void main(){
my_unordered_map<int,int> kk;
}
相关文章:
- 继承期间显示未知行为的子类
- 通过指向指针数组的指针访问子类的属性
- 从父类方法返回子类对象
- c++, 在子类中,如何在没有对象的情况下访问父类的方法?
- 将父类对象强制转换为子类的问题
- 避免在C++中重复子类定义
- 将QOpenGLWidget子类转换为使用Metal而不是OpenGL的子类是否可行?
- 如何初始化矢量的模板化子类
- C++ 继承:将子类传递给需要基类的函数并获取子类行为
- 有没有办法按值将纯抽象类的所有子类传递给 C++ 中的函数?
- 使用子类覆盖基类中定义的函数
- 子类地址等于虚拟基类地址?
- 将子类方法声明为基类的友元
- C++子类共享变量?
- 如何检查模板专用化是否是基本模板的子类?
- 仅让特定类'Fabric'构造类'Foo'及其所有子类的实例
- 使用模板参数重载C++方法:如何使其适用于模板的子类?
- 基类中的默认析构函数禁用子类中的移动构造函数(如果有成员)
- 如何在C++子类中访问父类的私有变量
- 将父类的子类的数据复制到具有相同父类的另一个类