Re: [C++-sig] Re: Returning reference to member variable that's a
basic type
by Joel Gerard other posts by this author
Oct 6 2003 5:09PM messages near this date
[C++-sig] Re: Returning reference to member variable that's a basic
type
|
[C++-sig] Returning reference to member variable that's a basic type
Hmmm... I see what you mean. Couldn't you map an int reference to something like:
class IntegerReference :
def __setattr__(self, name, value) :
#BPL code here
def __getattr__ (self, name) :
#BPL code here
Then you could do something like:
i = Obj.FnThatReturnsAnIntRef()
i.value = 45
IntegerReference would keep a pointer to the original integer (I'm assuming you can do this:
keep
the address of the original variable as a python int or something, and then deference it in
C?).
Then set and get would deference the pointer, and get/set the value respectively.
It's a pity that one can't overload the assignment operator in python (not that I've seen an
yhow).
The "i.value" mechanism is not the cleanest, and I'd prefer to do "i=5" but I'd rather have
some
mechanism than nothing. Perhaps there is a better way. I fairly new to python.
Thanks for the quick response. ;)
Joel
--- David Abrahams <dave@[...].com> wrote:
> Joel Gerard <llywelyn.geo@[...].com> writes:
>
> > I hope this doesn't get me the dumb question of the day award but...
> >
> > How do you return a pointer/reference to a member variable(a basic type) and modify it f
rom
> > python?
>
> You don't. Basic types get mapped to Python ints, longs, and
> strings, all of which are immutable. YOu can't modify them.
>
> Decide what interface you'd like to see for this code in Python, code
> up a pure-Python mock-up which does what you want, and we can discuss
> how to achieve it with BPL.
>
> --
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig@[...].org
> http://mail.python.org/mailman/listinfo/c++-sig
=====
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
Pierre Barbier de Reuille
Lijun Qin
David Abrahams
Pierre Barbier de Reuille
Niall Douglas
David Abrahams
Joel Gerard
Joel Gerard
|