Differences between revisions 2 and 3
Revision 2 as of 2002-09-26 00:58:07
Size: 1089
Editor: MikeRovner
Comment:
Revision 3 as of 2002-09-26 20:31:51
Size: 1415
Editor: MikeRovner
Comment:
Deletions are marked like this. Additions are marked like this.
Line 34: Line 34:
2. 2. ''What is the relation between this no_init and boost::noncopyable?''

The only relationship is that they both deal with constructors.
 * no_init means "do not try to define a Python __init__ function"
 * noncopyable means "do not try to register a converter which can
    convert C++ T return values to python".
----

From comp.python.c++ newsgroup:


1. The constructors of some classes I am trying to wrap are private because instances must be created by using a factory. Is it possible to wrap such classes using bpl v2?

Sure. Of course you can only create the instances using the factory...

If you look at libs/python/test/test_pointer_adoption.cpp you'll see the factory function "create" is being used to generate new instances of class A. It uses return_value_policy<manage_new_object> to instruct Python to adopt the A* to hold the instance.

A* create(std::string const& s)
{
    return new A(s);
}

BOOST_PYTHON_MODULE_INIT(test_pointer_adoption_ext)
{
        def("num_a_instances", num_a_instances);

        // Specify the manage_new_object return policy to take
        // ownership of create's result
        def("create", create, return_value_policy<manage_new_object>());
        
        class_<A>()
            .def("content", &A::content)
            .def("get_inner", &A::get_inner, return_internal_reference<>())
        ;
}


2. What is the relation between this no_init and boost::noncopyable?

The only relationship is that they both deal with constructors.

  • no_init means "do not try to define a Python init function"

  • noncopyable means "do not try to register a converter which can
    • convert C++ T return values to python".


boost.python/FAQ (last edited 2010-10-26 02:02:04 by c-67-188-38-165)

Unable to edit the page? See the FrontPage for instructions.