[C++-sig] Wrapping method that returns const int& (boost::python)

Abhishek Srivastava abhishek.srivastava at nechclst.in
Mon Oct 25 20:11:15 CEST 2010


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 at python.org on behalf of Panos
Sent: Mon 10/25/2010 7:04 PM
To: cplusplus-sig at 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 at 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. . 
-----------------------------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20101025/8dfb7178/attachment.html>


More information about the Cplusplus-sig mailing list