assignment to this

BCS ao at pathlink.com
Tue Jul 17 13:51:32 PDT 2007


Reply to Jarrett,

> "Ender KaShae" <astrothayne at gmail.com> wrote in message
> news:f7j521$1dnc$1 at digitalmars.com...
> 
>> since my idea of assigning to this fell through I am wondering if
>> there is another way that I can give an immutable type opPostInc,
>> opAddAssign, etc. without altering all references to it.  any ideas?
>> 
> Even if assigning to this did work, it wouldn't solve that problem.
> 'this' is just another local parameter to a member function.
> 

that is in fact exactly what happens:

|import std.stdio;
|class Foo
|{
|	int i;
|	void go()
|	{
|		writef("%d\n", i);
|		this = foo;
|		writef("%d\n", i);
|	}
|}
|Foo foo;
|void main()
|{
|	Foo f = new Foo; f.i=1;
|	foo = new Foo;   foo.i=2;
|	f.go();
|	f.go();
|}

output:
1
2
1
2




More information about the Digitalmars-d-learn mailing list