Is it possible to store CBaseObject* (base class pointers) in slist, hashtable, rbtree and avl tree? I am deriving CBaseObject from slist_base_hook, set_base_hook etc. But when using member_hook<CBaseObject*,...) and rbtree<CBaseObject*,...>, I am getting compiler errors. Boost documentation provides examples about objects and smart pointers. But can we store raw pointers in intrusive containers?
Swadhin Bhide wrote:
Is it possible to store CBaseObject* (base class pointers) in slist, hashtable, rbtree and avl tree?
No. Intrusive containers store (actually link) objects that have a member or base hook.
I am deriving CBaseObject from slist_base_hook, set_base_hook etc. But when using member_hook <CBaseObject*,...) and rbtree<CBaseObject*,...>, I am getting compiler errors. Boost documentation provides examples about objects and smart pointers.
boost::intrusive::list<CBaseObject> offers the same functionality as storing pointers in a standard list. If you call: intrusive_list.begin()->virtual_func(); You will call to virtual functions, even if the container is boost::intrusive::list<CBaseObject>.
But can we store raw pointers in intrusive containers?
No. See http://www.boost.org/doc/libs/1_35_0/doc/html/intrusive/usage_when.html For an example where base and derived classes are stored in an intrusive container. regards, Ion
participants (2)
-
Ion Gaztañaga
-
Swadhin Bhide