On Sun, Dec 6, 2009 at 9:18 PM, johnmatthews2000 <[email protected]> wrote: > --- In [email protected], "py2akv" <g...@...> wrote: >> >> Luciano, >> >> > const int i2 = 2; >> > int& ri2 = (int&) i2; >> > ri2 = 102; // should change the value of both 'i2' and 'ri2' >> >> Should it, my friend? >> >> As far as I'm concerned, ri2 is a reference type for an int, in this case >> const int i2 and it's correct the (int&) cast; if i2 weren't const, the cast >> wouldn't be necessary. >> >> Such being, i2 should never change, retaining the initialized value of 2. >> >> See there's nothing wrong with ri2 getting another value: it's not itself >> const; were ri2 const int& ri2 = (int&) i2, then the assignment ri2 = 102 >> would be impossible. >> >> So, 102 affects ri2 only, but not i2, const. > > But ri2 is a reference to i2. So whether i2=2 or i2=102, I would expect > ri2=i2.
Since you're messing with undefined behaviour, why would you expect any particular behaviour? <snip stuff that looks like the a[i] = i++; justifications that we sometimes get on here.> -- PJH http://shabbleland.myminicity.com/ http://www.chavgangs.com/register.php?referer=9375 http://www.kongregate.com/?referrer=Shabble
