This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Why does this not compile?


At 15:26 -0700 19-05-2002, Harron, Vince wrote:
>Either way, I'm having trouble imagining why the spec forbids this in the
>first place.  So what if I modify a temporary?  Any ideas?

Well, because a temporary object is just a value, it's an expression. 
Trying to change binary(b) is kinda like trying to change 3+4.

For example, take:

void foo(myclass& x);

int main() {
   myclass x;
   foo(x);
   foo(myclass(x));
   return 0;
}

the first foo works, the second doesn't. if it's not entirely clear 
why not, replace "myclass" by "int" and look at it again :)

Just because in practice it *is* possible to change a temporary 
myclass while it's not possible to change a temporary int, doesn't 
mean it's also allowed.

  - xmath


Matthijs van Duin
- PGP Key: 0x2D6F0BA7
- FP: 205D F7BA FFAD 9070 AB9E  C5A8 BDB0 CA1B 2D6F 0BA7 -


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]