[C++-sig] Exposing a class with private ctor and private dtor

Roman Yakovenko roman.yakovenko at gmail.com
Thu May 4 07:41:21 CEST 2006


On 5/4/06, Abhi <abhi at qualcomm.com> wrote:
> Question 1. How do I expose a class which has a private dtor? The class has
> static method to destroy it instead?

I don't know, please post the question in a separate thread.

>
> Observation 1: Running py++ on it does not produce the right code! It takes
> care of the case of private ctor in the above case, but does not take care
> of the private dtor.

I thought, but did not tested, that
bp::class_< PrivateCtorDtor, boost::noncopyable >( "PrivateCtorDtor",
bp::no_init )
should work, obviously I was wrong ( twice ).

I hope, you will find the answer to your first question and will post
it here. Thus I will be able
to implement the solution in py++

> Question 2: I think this can be done by wrapping the class with a derived
> class.
> For example:
>
> bp::class_<PrivateCtorDtor_YWrapper>("PrivateCtorDtor", bp::no_init)
>
> where PrivateCtorDtor_YWrapper class is derived from the PrivateCtorDtor
> class.
> And PrivateCtorDtor_YWrapper dtor calls the free static method of the
> PrivateCtorDtor class.
>
> But I __could not get it to work__.

May be it could not be done this way :-)?

> Question 3: Is it possible to do this without creating the derived class as
> above? For example, by doing a .def on some python function name (either
> "__del__" or something like that)

Interesting idea. You want to map PrivateCtorDtor::free function to
__del__ method, right?

> thanks
> - Abhi


--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list