[C++-sig] wrapping reference members

Matthew Scouten (TT) Matthew.Scouten at tradingtechnologies.com
Wed Jul 22 16:30:18 CEST 2009


I would think that .def_readwrite would do what you need. If it doesn't
look at using .def_property and get/set pair. Caveat: making sure that
'a' stays a valid reference is your problem. Python will happily crash
horribly (if you are lucky) in response to bogus pointers or references.


-----Original Message-----
From:
cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org
[mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py
thon.org] On Behalf Of Sebastian Kraemer
Sent: Wednesday, July 22, 2009 9:16 AM
To: cplusplus-sig at python.org
Subject: [C++-sig] wrapping reference members

Hi all,
I'm a beginner of c++ and boost::python, so this may be a stupid
question. When I have the following class:

class Foo{
    public:
        float &a;
    };

Is there some way to expose "a" in python? I would like to use it like a
normal python attribute, e.g. set it's value with "Foo().a = 3.1".

Thanks for any help,
Sebastian

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


More information about the Cplusplus-sig mailing list