[C++-sig] Exposing a class with private ctor and private dtor
Abhi
abhi at qualcomm.com
Thu May 4 19:34:59 CEST 2006
--On Thursday, May 04, 2006 8:41 AM +0300 Roman Yakovenko
<roman.yakovenko at gmail.com> wrote:
> 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.
will do.
>
>>
>> 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++
Once I get some responses, I will post a summary.
>
>> 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 :-)?
I am not sure if this is a Boost.Python limitation ==> cannot be done at
all using Boost.Python, hence py++.
>
>> 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?
Actually, that did not work at all. Seems like python calls __del__ and
then calls the C++ destructor. Thus, I cannot avoid a call to the C++
destructor.
Is there anyway to tell python to decrement the reference count on the
object to zero rather than deleting it. Maybe using auto_ptr might help.
Any Ideas?
>
>> thanks
>> - Abhi
>
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list