 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Thu Dec 28, 2006 10:10 am Post subject: Reseating references |
|
|
Hi All
I was always lead to believe that references were unable to be
reseated. However i recently tried compiling the following code using
VC8
int i = 22;
int j = 44;
int& ri = i;
cout << "ri = " << ri << endl;
ri = j;
cout << "ri = " << ri << endl;
which resulted in the following output:
ri = 22
ri = 44
Is this correct behaviour? If yes, what does term "reseatable" mean?
Thanks
Andy
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
James Kanze Guest
|
Posted: Mon Jan 01, 2007 2:20 am Post subject: Concernig boost::optional, was Re: Reseating references |
|
|
Chris Uzdavinis wrote:
| Quote: | (Though there are some unusual techniques to get
the effect in certain cases, like what boost::optional does when it
holds references.)
|
Just wondering, but you don't need boost::optional to support
optional (or reseatable) references; C++ has a built-in type
which supports it directly: pointers. I don't think that using
boost::optional when you want a pointer will make programs
clearer.
Also, of course, there's no reason to get tricky and reseat a
reference. If support for references is desired (say on the
grounds of completeness or orthogonality), partial
specialization and using a pointer in the actual implementation
is largely sufficient. (I rather suspect that the authors of
boost::optional are aware of this, and that any tricky
techniques involved are for general support of types not having
a default constructor.)
--
James Kanze (Gabi Software) email: james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|