Topic: Modifying references (was: Guru of the Week #22: Object Lifetimes - Part I)
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/10/11 Raw View
David R Tribble <david.tribble@central.beasys.com> writes:
> Bill Wade <bill.wade@stoner.com> wrote:
> > ...
> > A reference member can be changed by destruction/construction.
>
> I was not aware that a reference member could be modified in a destructor.
> Perhaps someone could show me an example?
In can't, but after the destructor of the object in run (does a
reference have a destructor ?), the reference can be rebinded to
annother object.
Quoting Bill Wade:
]>struct foo
]>{
]> const int& r;
]> foo(int j): r(j){}
]>};
]>
]> foo x(7);
]> x.~foo();
]> new(&x) foo(5); // Gives x.r a new binding
]>
]>I believe that a compiler which treated x.r as a constant (even if the
]>destruction/construction were hidden in a subroutine) would not comply
with
]>the standard. This sample does not invoke undefined behavior.
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: David R Tribble <david.tribble@central.beasys.com>
Date: 1997/10/11 Raw View
Bill Wade <bill.wade@stoner.com> wrote:
> ...
> A reference member can be changed by destruction/construction.
I was not aware that a reference member could be modified in a destructor.
Perhaps someone could show me an example?
--------------------. BEA Systems, Inc. ,-. +1-972-738-6125 Office
David R. Tribble \ ,------------------' \ +1-972-738-6111 Fax
http://www.beasys.com `-' Dallas, TX 75248 `-----------------------
david.tribble@noSPAM.beasys.com http://www.flash.net/~dtribble
Support the anti-Spam amendment, join at http://www.cauce.org/
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]