Re: [Boost-users] Exposing Class with Private ctor and dtor

Well marking the copy constructor as private is not required since dtor is already marked as private. You will not be able to copy construct by saying something like A *a = new A(); A a' = A(*a) //This will fail because dtor of A is private. However making the python wrapper class as boost::noncopyable works. It seems, if you do not mark the wrapper class as "noncopyable", boost python internally generates some code which requires public dtor. Kumar -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Dale McCoy Sent: Wednesday, May 17, 2006 6:24 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Exposing Class with Private ctor and dtor
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 _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

"Anand, Kumar"
Well marking the copy constructor as private is not required since dtor is already marked as private.
You will not be able to copy construct by saying something like A *a = new A(); A a' = A(*a) //This will fail because dtor of A is private.
However making the python wrapper class as boost::noncopyable works. It seems, if you do not mark the wrapper class as "noncopyable", boost python internally generates some code which requires public dtor.
It generates code that uses the copy ctor to create a Python object managing a new instance of the class. Naturally, that object can't be destroyed, so you get an error. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
Anand, Kumar
-
David Abrahams