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

Abhi abhi at qualcomm.com
Thu May 4 02:31:20 CEST 2006


Question 1. How do I expose a class which has a private dtor? The class has 
static method to destroy it instead?

class PrivateCtorDtor
{
public:
  int nonStaticVariable;
  static int staticVariable;
  static PrivateCtorDtor* allocate();
  static void free(PrivateCtorDtor* );

  static int getStaticVariable()
  {
    return staticVariable;
  }


  private:
  ~PrivateCtorDtor();

private:
  PrivateCtorDtor();


};

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.

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

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)


thanks
- Abhi




More information about the Cplusplus-sig mailing list