Vikram posted:
Kirit S=E6lensminde wrote:
sidney@jigsaw.nl wrote:
Vikram wrote:
I dont think you can have references inside a STL container (like
Vector). Mainly because of issues while copying. A reference,
unlike a pointer, can only be set once.
This is not true. A reference can be set many times unless it is
const. You must however assign a value to it when it is constructed.
Sorry..but how? I am not aware of any way to re-assign a reference
variable. Infact, Scott Meyer's "More effective C++" has that as the
1st item.
Maybe I am missing something here
I presume, (although I don't know if he meant it in a smart-alaky way),
that he mean that you can do:
int i;
int &r = i;
int a = 1, b = 2, c = 3, d = 4;
r = a; r = b; r = c; r = d;
However, any C++ programmer who's out of diapers will tell you that
you're setting the value of "i", NOT changing the object to which the
reference refers.
If you ever change the object to which a reference refers, I'll give you
my house, and also eat my hat for good measure.
badly in my haste to answer the second half.