Boost logo

Boost :

From: Xavier Warin (xavier.warin_at_[hidden])
Date: 2001-04-09 07:39:28


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<world>
>) (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::python::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


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