Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-04-09 07:46:56


I think someone has previously answered this question very recently.

You can't write world_mod(boost::python::constructor...
You must write world_mod.def(boost::python::constructor...

-Dave
----- Original Message -----
From: "Xavier Warin" <xavier.warin_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, April 09, 2001 8:39 AM
Subject: Re: [boost] question BPL mapping

> David Abrahams wrote:
>
> > Your code looks correct to me, except for that your world constructor
takes
> > Data by value and you specified in initriskneut that it was passed by
> > const&.
> >
> > Regards,
> > Dave
>
> Sorry Dave !
>
> I made a mistake while picking up pieces for the mail. So the world
> constructor takes Data by reference (for example)
>
> class Data {
> private :
> const double w ;
> public :
> Data( double v ) : w(v) {} ;
> ~Data() {}
> } ;
>
> class world
> {
> private:
> const double tu ;
> public :
> world( Data & data, double ti) :tu(ti) {};
> };
>
>
> extern "C"
> void initriskneut()
> {
> try
> {
> // Create an object representing this extension module.
> python::module_builder this_module("alltest");
>
> // Create the Python type object
> boost::python::class_builder< Data > Data_class(this_module, "Data" );
> Data_class.def(boost::python::constructor< double >());
>
> // Create the Python type object for our extension class world
> boost::python::class_builder<world> world_mod(this_module, "world");
> // constructor
> // How to define the mapping Between the Data python object (created
via
> BPL) and the
> // a Data C++ object to give to the constructor
> world_mod(boost::python::constructor< Data & , double >());
> }
> catch(...)
> {
> boost::python::handle_exception(); // Deal with the exception for
Python
> }
> }
>
> I get the following error with GCC :
> ../BPL_NEW/pric.cc: In function `void initriskneut(...)':
> ../BPL_NEW/pric.cc:40: no match for call to
>
`(boost::python::class_builder<world,boost::python::detail::held_instance<wo
rld>
> >) (boost::python::constructor<Data
>
&,double,boost::python::detail::void_t,boost::python::detail::void_t,boost::
python::detail::void_t,boost::python::detail::void_t,boost::python::detail::
void_t,boost::python::detail::void_t,boost::python::detail::void_t,boost::py
thon::detail::void_t>)'
>
> ***
>
> I get the following error with KCC
> "../BPL_NEW/pric.cc", line 40: error: expression must have (pointer-to-)
> function type
> world_mod(boost::python::constructor< Data & , double >());
> ^
>
> This only happens while using Data in a contructor of a second class. No
> problem if the Data object is used as an input for a function.
> I though that i missed something (that i had to do something more for the
> mapping). Could you confirm that it should work
> (for me it shouldn't : a link is missing...)
> Best regards
>
> Xavier
>
>
> To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk