[C++-sig] boost python references
david stummer
stummer at gmail.com
Sun Apr 16 12:51:29 CEST 2006
Let me simplify my question. In python you can do something like
class Seat:
position="a"
class Window:
seat=None
s=Seat()
s2=Seat()
w=Window()
s2 = s
w.seat=s
print s.position
print s2.position
print w.seat.position
s.position="b"
print s.position
print s2.position
print w.seat.position
and the output would be :
a
a
a
b
b
b
indicating that s2 and w.seat reference s. This is what i want. However,
when i try this with c++ classes it doesn't work, i.e.
class Seat
{
public:
std::string position;
};
Seat::Seat()
{
position="david";
}
class Window
{
public:
Seat seat;
};
class_<Seat>("Seat")
.def_readwrite("position", &Seat::position)
;
class_<Window>("Window")
.def_readwrite("seat", &Window::seat)
;
when using similar python code above with these classes instead of the
python-defined ones, i get the following output:
a
a
a
b
b
a
The Seat object in the Window object isn't reference: it is a new object.
Why is this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060416/008724f7/attachment.htm>
More information about the Cplusplus-sig
mailing list