Exposing Class with Private ctor and dtor

Hi, A class has static method to create and a static method to destroy. And the constructors and destructor of the class is marked as private. How do I expose such a class in Python? Eg. class A { private: static A* instance; A() { }; ~A {}; public: static A* create () { If(instance != 0) instance = new A(); return instance; } static void destroy() { delete instance; instance = 0; } }; In Boost Python, I tried the following but the code doesn't compile unless I make the destructor of class A as public. namespace bp = boost::python; bp::class_<A> ("A", bp::no_init) .def("create", &A::create) .def("destroy", &A::destroy) .staticmethod("create") .staticmethod("destroy") ; Any suggestions? Thanks Kumar

A class has static method to create and a static method to destroy. And the constructors and destructor of the class is marked as private. How do I expose such a class in Python? <snip code>
In the code you posted, the default constructor is indeed private, but the copy constructor is not. Was that intentional? If so, then it's still possible to write A otherA(A::create()); which requires public access to ~A() in order to destroy otherA. If it was not intentional, does explicitly privitizing the copy-constructor work? (Or make it clear where Boost::Python wants to copy-construct an A?) Dale
participants (2)
-
Anand, Kumar
-
Dale McCoy