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

Abhi abhi at qualcomm.com
Mon May 8 23:03:40 CEST 2006


hmmm....
Not sure on how to use this in my code/wrappers?

The only way I can think of exposing a class with a private dtor to python 
is via composition. For example,

class A
{
public:
   void foo1();

   static destroy(A* );

private:
   ~A();
};

--------------------

class A_wrap
{
private:
  A* a;

public:
   A_wrap()
    {
        a = new A();
    }

   void foo1()
    {
        a->foo1();
    }

   ~A_wrap()
    {
        A::destroy(a);
    }

};


And then expose A_wrap as "A" to python.

Not very scalable!

thanks
- Abhi




thanks
- Abhi






--On Sunday, May 07, 2006 4:45 PM +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?
>
>>
>> Question 4: Is it even possible using Boost.Python?
>>
>
> I think you can do it. I would like to be wrong, but..
>
> Here is, I think, relevant piece of code from
> libs\python\src\object\class.cpp
>
>       static void instance_dealloc(PyObject* inst)
>       {
>           instance<>* kill_me = (instance<>*)inst;
>
>           for (instance_holder* p = kill_me->objects, *next; p != 0; p =
> next)
>           {
>               next = p->next();
>               p->~instance_holder();
>               instance_holder::deallocate(inst, dynamic_cast<void*>(p));
>           }
>
>
>>
>> thanks
>> - Abhi
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/







More information about the Cplusplus-sig mailing list