this as lvalue?

Jonathan M Davis jmdavisprog at gmail.com
Fri Sep 3 15:35:59 PDT 2010


On Friday 03 September 2010 15:18:25 Andrei Alexandrescu wrote:
> On 9/3/10 17:16 CDT, bearophile wrote:
> > Andrei Alexandrescu:
> >> For classes this must be an rvalue.
> > 
> > OK. Why?
> 
> If you could change this from within a method you'd pretty much ruin
> everything about object orientation.
> 
> Andrei

On the bright side, except for the constructor, it should only change what 
happens in that one member function and anything member functions that are 
called from it (or called from something that's called from it), so it's not 
like it's going to break everything.

But really, it shouldn't work. There's no value to it. It just allows for bugs, 
even if you have to work at it to get them. I'm 99% certain that you can't 
reassign this in C++, C#, or Java, and I'd sooner expect someone to be surprised 
that it's possible that actually want to be able to. It's useful for structs, 
but for classes, it has no value. And as you say, it effectively breaks object 
orientation.

- Jonathan M Davis


More information about the Digitalmars-d mailing list