[C++-sig] Private construction for python objects?

Robert Dailey rcdailey at gmail.com
Fri Oct 24 21:29:44 CEST 2008


Hi,

I have a C++ class that I'm exposing to Python via the Boost.Python library.
This specific class is only created from C++. In other words, it doesn't
serve the user very much good to construct an instance of this class from
Python. A typical use case for obtaining an instance of this class from
python is as follows:

import myCustomModule
fooInstance = myCustomModule.GetFooInstance()

However, I want to prevent the user from being able to do this:

import myCustomModule
fooInstance = myCustomModule.Foo()

Let's assume the class in question with private construction is Foo. The
latter code snippet would be an example of the user directly constructing an
instance of Foo(). Is there a way to prevent this through the
BOOST_PYTHON_MODULE() definition? I'm not even really sure if this can be
done natively through Python. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081024/86878c0d/attachment.htm>


More information about the Cplusplus-sig mailing list