[C++-sig] boost python references

david stummer stummer at gmail.com
Sat Apr 15 20:13:36 CEST 2006


hi guys,

i am trying to use references with boost python.

in python you can do:

class person:
    name='david'

a=person()
b=a
print a.name
a.name='john'
print b.name

because b is a reference, it will always change as a changes. hence
b.nameis also john.

i want this functionality between boost and python.

I have the C++ class:

class_<Window>("Window")
    .def_readwrite("seat", &Window::seat)
 ;

where seat is an object of class Seat. Seat contains an integer attribute
named position. It's default value is 45.

My python code is

s=Seat()
w=Window()
print s.position # prints 45
w.seat.position=s.position
s.position=66
print w.seat.position # prints 45
print s.position # prints 66

this shows that it isn't passed by reference as print w.seat.position needs
to be 66

How can i used references?

thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060415/ca16d606/attachment.htm>


More information about the Cplusplus-sig mailing list