[C++-sig] Private construction for python objects?
rcdailey at gmail.com
Fri Oct 24 21:29:44 CEST 2008
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:
fooInstance = myCustomModule.GetFooInstance()
However, I want to prevent the user from being able to do this:
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...
More information about the Cplusplus-sig