Wrapping method that returns const int& (boost::python)
I have a simple test case: class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_<Foo>("Foo") .def("getX", &Foo::getX) ; } The problem is that I cannot wrap getX and I get a compiler error. How is it possible to wrap getX WITHOUT changing anything in Foo? Thanks in advance! Panos Christopoulos Charitos www.ancient-ritual.com www.anki3d.org
Panos wrote:
I have a simple test case:
class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;}
private: int x; };
BOOST_PYTHON_MODULE(module) { class_<Foo>("Foo") .def("getX", &Foo::getX) ; }
The problem is that I cannot wrap getX and I get a compiler error. How is it possible to wrap getX WITHOUT changing anything in Foo?
Thanks in advance!
Panos Christopoulos Charitos www.ancient-ritual.com www.anki3d.org _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Hi! I totally affiliate myself to this problem. The only difference is that i do not return a const reference but rather a reference. So maybe we can find a solution for this together :-) Greetings! -- Erik Tuerke Department of Neurophysics Max-Planck-Institute for Human Cognitive and Brain Sciences Stephanstrasse 1A 04103 Leipzig Germany Tel: +49 341 99 40-2440 Email: tuerke@cbs.mpg.de www.cbs.mpg.de
Panos, Erik, the issue here is likely that Python's "int" objects are immutable. Therefore, you can't pass around ints by reference, only by-value. If the compiler is confused, perhaps you need to explicitly set a return-value policy that makes this clear ? Stefan -- ...ich hab' noch einen Koffer in Berlin...
Does this works for you?? class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_<Foo>("Foo") .def("getX", &Foo::getX, return_value_policy<return_by_value>()) ; } With Regards, Abhishek Srivastava -----Original Message----- From: cplusplus-sig-bounces+abhishek.srivastava=nechclst.in@python.org on behalf of Panos Sent: Mon 10/25/2010 7:04 PM To: cplusplus-sig@python.org Subject: [C++-sig] Wrapping method that returns const int& (boost::python) I have a simple test case: class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_<Foo>("Foo") .def("getX", &Foo::getX) ; } The problem is that I cannot wrap getX and I get a compiler error. How is it possible to wrap getX WITHOUT changing anything in Foo? Thanks in advance! Panos Christopoulos Charitos www.ancient-ritual.com www.anki3d.org _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or NECHCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of NECHCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. . -----------------------------------------------------------------------------------------------------------------------
participants (4)
-
Abhishek Srivastava -
Erik Tuerke -
Panos -
Stefan Seefeld