[C++-sig] Question regarding protected destructor
David Abrahams
david.abrahams at rcn.com
Thu Jul 18 23:42:05 CEST 2002
From: "gideon may" <gideon at computer.org>
> Hi,
>
> I have a class in a library with a protected destructor which
> would like to wrap. Basically it looks like :
>
> class Test {
> public:
> Test() {}
> protected:
> ~Test() {}
> };
>
> When I try to create a python module with the following :
>
> boost::python::module pyOSG("pyOSG");
> pyOSG.add(class_<Test>("Test").def_init(args<>()));
>
>
> I get the following error with VC7:
>
> C:\cvs_rep\boost\boost\boost\python\object\value_holder.hpp(41) : warning
> C4624: 'boost::python::objects::value_holder<Held>' :
> destructor could not be generated because a base class destructor is
> inaccessible
>
> Is there any way to solve this ?
There are all kinds of ways. You could change the library source code, for
example.
However, the presence of a protected destructor is a sure sign that the
author of the class didn't want you to create instances of Test directly.
If you want to expose Test to Python as an abstract base class, you could
try exposing a class derived from Test using the HeldType parameter
described at www.boost.org/libs/python/doc/v2/class.html#class_-spec...
HTH,
-Dave
More information about the Cplusplus-sig
mailing list