C ++抽象基类的集合 [英] C++ collection of abstract base classes

查看:101
本文介绍了C ++抽象基类的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建不使用指针就将基类用作集合值来实现抽象基类的STL类集合?

how can I create STL collection of classes which implement abstract base class using the base class as collection value, without using pointers?

Boost中有什么可以让我实现的吗?具体来说就是地图.

is there something in Boost that allows me to implement it? The collection specifically is map.

谢谢

推荐答案

您无法完全避免使用指针.如果要避免对象切片,则必须将指针存储在集合中. Boost具有一个可以很好地隐藏指针的容器: ptr_map

You cannot avoid pointers completely. You must store pointers in the collection if you want to avoid Object slicing. Boost has a container that hides the pointers pretty well: ptr_map

这篇关于C ++抽象基类的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆