[C++-sig] Question regarding protected destructor

gideon may gideon at computer.org
Fri Jul 19 00:02:11 CEST 2002


Hi Dave,


>> 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...
>

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. I looked into the HeldType but I'm not sure 
it
is of any help to me. 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/).

ciao,

gideon






More information about the Cplusplus-sig mailing list