Boost logo

Boost :

Subject: [boost] Re : Re : Using an element of a class A in a constructor of a class B (reflection with boost::python)
From: christophe jean-joseph (jjchristophe_at_[hidden])
Date: 2012-03-12 08:24:55


Thank you very much for the answers. @Steven Watanabe. Sorry, I should have been more clear by showing the solution I found for a non constructor. Let's say I have B::Foo(A& a){} (where foo isn't a ctor of B) I reflect it as follow: class_A <A, boost::noncopyable>("A", no_init)  //this line can be modified     .def("Foo", &B::Foo); class_B <B, boost::noncopyable>("B", init< >())  //this line can be modified     .def("Foo", &B::Foo); Meanning I have to declare Foo in both A and B for boost:;python. My problem is that I can't do the same for a ctor. @Jim Bosch thank you for your advices. As I am new with boost, and with the mailing list, I didn't know where I should ask my question. I will try my luck there. Christophe Jean-Joseph   ________________________________ De : Jim Bosch <talljimbo_at_[hidden]> À : boost_at_[hidden] Cc : christophe jean-joseph <jjchristophe_at_[hidden]> Envoyé le : Dimanche 11 mars 2012 4h37 Objet : Re: [boost] Re : Using an element of a class A in a constructor of a class B (reflection with boost::python) On 03/10/2012 09:32 PM, christophe jean-joseph wrote: > > > Thank you for your message, but it does not answer my question, I know how to reflect a C++ constructor under Python through boost and have absolutly no problem with that. > My question is about reflecting Bctor(A&  a, double&  x) where Bctor is the constructor of class B and A another class. > As I said, I can do that for any other function, except a constructor. > I already read many website, including python and boost websites, before asking my question here. > The link you provided, and that I already read before, only explain how to reflect a constructor. > That would be of great help if anyone could give me some clue. > If the "double &" argument is intended to return a value, then I'm afraid you're pretty much stuck, unless you're willing to put the value in some kind of mutable proxy object (e.g. a one-element list).  Python floats are immutable, so they simply can't be used as output arguments.  And since constructors can't return values, you can't just change the signature.  That's a Python limitation, not a Boost.Python one. If you don't care about the value of the "double &" argument after the call, you can just pretend that it's passed by value, i.e.: namespace bp = boost::python; bp::class_<B>("B")     .def(bp::init<A&,double>())     ; By the way, you'll probably get more attention on Boost.Python questions on the cplusplus-sig_at_[hidden] mailing list. Jim


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