On 2/19/2012 9:46 AM, Johan Råde wrote:
The following code works fine:

using namespace boost::python;

class X {};

X* make_X(int n, float f) { return new X; }

BOOST_PYTHON_MODULE(Test)
{
class_<X>("X")
.def(
"__init__",
make_constructor(&make_X)
//,(arg("n"), arg("f") = 1.0f)
);
}

But if I uncomment the commented line, then the code does not compile.
How do I fix that?

I figured out how to do it:

    using namespace boost::python;

    class X {};

    X* make_X(int n, float f) { return new X; }

    BOOST_PYTHON_MODULE(X)
    {
        class_<X>("X")
        .def(
            "__init__",
            make_constructor(
                &make_X,
                default_call_policies(),
                (arg("n"), arg("f") = 1.0f)
            )
        );
    }

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to