[C++-sig] Question regarding protected destructor
David Abrahams
david.abrahams at rcn.com
Fri Jul 19 00:17:27 CEST 2002
From: "gideon may" <gideon at computer.org>
> Unfortunately I'm unable to change the code, it's a library which is in
> constant
> flux. All the class(es) destructors are protected since it has it's own
> reference
> counting and memory management.
Oh! in that case...
> I looked into the HeldType but I'm not sure
> it is of any help to me.
Yes, it should be! You need to make a smart pointer class (template) which
you can use as HeldType.
> The classes I would like to use with boost are part
> of
> a large class hierarchy, each of them derived from a base class with the
> protected destructor. The library which I am trying to wrap is the
> OpenSceneGraph (http://www.openscenegraph.org/).
If you supply a smart pointer template, say, "scene_graph_ptr<T>", which
does the reference-counting, you can pass that as HeldType. The only other
requirement is that you supply a nested typedef in your smart pointer:
typedef T element_type;
so that pointee<T> knows what type it's pointing at.
Now you can wrap functions which accept T cv*, T cv&, and
scene_graph_ptr<T> arguments.
HTH,
Dave
More information about the Cplusplus-sig
mailing list