[C++-sig] Re: Re: Re: Re: long long unsigned issue...

Milind Patil milind_patil at hotmail.com
Tue May 6 01:58:13 CEST 2003


"David Abrahams" <dave at boost-consulting.com> wrote in message
news:u65orxage.fsf at boost-consulting.com...
> "Milind Patil" <milind_patil at hotmail.com> writes:
>
> > However, I could have a Y_Wrapper class that I can add constructors to.
> > Is this possible?...
>
> Yes, that's a good approach, and the only one we currently support
> well.  Eventually it should be possible to add factory functions as
> constructors, but it isn't yet.
>
> > struct Y_Wrapper: Y {
> >   public:
> >     Y_Wrapper(PyObject* self_) : self(self_) { }
> >     /* ... more constructors ... */
> >     Y_Wrapper(PyObject* self_, boost::python::long_  y) : self(self_) { /*
> > some code to convert long_ to Y */ }
> >
> >     PyObject* self;
> > };
> >
> > BOOST_PYTHON_MODULE(hello)
> > {
> >     class_< Y, Y_Wrapper >("Y", init<  >())
> >         .def(init< const Y & >())
> >         //... more init defs ...
> >         .def(init< long_ >())
> >        //...
> >     ;
> > }
>
>
> --
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com

OK. Now when I try to add a Y_Wrapper with a constructor from long_ (with no real conversion),  at
runtime
it craps out saying

TypeError: No to_python (by-value) converter found for C++ type:
Q45boost6python7objectst18reference_to_value1ZQ35boost6python5long_

ie. with

struct Y_Wrapper: Y {
    Y_Wrapper (PyObject* self_) : Y(), self(self_) {}
    Y_Wrapper (PyObject* self_, int y) : Y(y), self(self_) {}
    Y_Wrapper (PyObject* self_, long long unsigned int y) : Y(y), self(self_) {}
    Y_Wrapper (PyObject* self_, int s,  const Y& y) : Y(s,y), self(self_) {}
    Y_Wrapper (PyObject* self_, const Y& y) : Y(y), self(self_) {}
    Y_Wrapper (PyObject* self_, boost::python::long_ y) : Y(0), self(self_) {printf("hello long_");}

    PyObject* self;
};

...and ...

    class_< Y, Y_Wrapper >("Y", init<  >())
        .def(init< const Y & >())
        .def(init< int, const Y & >())
        .def(init< int >())
        .def(init< long long unsigned int >())
        .def(init< long_ >())
        .def_readwrite("y", &Y::y)
        .def("__int__", &Y::operator int)
    ;

Any pointer as to where I am going wrong?

Thanks again,
Milind







More information about the Cplusplus-sig mailing list