digitalmars.D.learn - assignment to this
- Ender KaShae (2/2) Jul 17 2007 to my utter astonishment when I compiled a program with an assignment to...
- Jarrett Billingsley (4/7) Jul 17 2007 Even if assigning to this did work, it wouldn't solve that problem. 'th...
- BCS (26/36) Jul 17 2007 that is in fact exactly what happens:
- Regan Heath (7/15) Jul 18 2007 Which is probably exactly why it doesn't work.
- Jarrett Billingsley (5/6) Jul 18 2007 Assigning to 'this' if the aggregate has an overloaded opAssign is perfe...
- Neal Alexander (5/15) Jul 24 2007 *(cast(void**)&this) = cast(void*) __instance__;
- Ender KaShae (2/9) Jul 30 2007 I vie for making 'this' a 'ref'
to my utter astonishment when I compiled a program with an assignment to this did ABSOLUTELY NOTHING. It seems to me that this is bug, the statement should either execute or give an error when there is an assignment to this. 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?
Jul 17 2007
"Ender KaShae" <astrothayne gmail.com> wrote in message news:f7j521$1dnc$1 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.
Jul 17 2007
Reply to Jarrett,"Ender KaShae" <astrothayne gmail.com> wrote in message news:f7j521$1dnc$1 digitalmars.com...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 2since 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.
Jul 17 2007
Jarrett Billingsley wrote:"Ender KaShae" <astrothayne gmail.com> wrote in message news:f7j521$1dnc$1 digitalmars.com...Which is probably exactly why it doesn't work. I agree with the OP tho, it should either work as you'd expect or error. In other words: - 'this' could be made 'ref' - 'this' could be made 'final' Regansince 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.
Jul 18 2007
"Regan Heath" <regan netmail.co.nz> wrote in message news:f7khch$tqs$1 digitalmars.com...I agree with the OP tho, it should either work as you'd expect or error.Assigning to 'this' if the aggregate has an overloaded opAssign is perfectly fine; but yes, I think that trying to reassign which instance 'this' points to should be an error.
Jul 18 2007
Jarrett Billingsley wrote:"Regan Heath" <regan netmail.co.nz> wrote in message news:f7khch$tqs$1 digitalmars.com...*(cast(void**)&this) = cast(void*) __instance__; works. Theres no reason to make an artificial restraint for it. Its usefull when patching a COM object's vtable out from under someone.I agree with the OP tho, it should either work as you'd expect or error.Assigning to 'this' if the aggregate has an overloaded opAssign is perfectly fine; but yes, I think that trying to reassign which instance 'this' points to should be an error.
Jul 24 2007
Regan Heath Wrote:I agree with the OP tho, it should either work as you'd expect or error. In other words: - 'this' could be made 'ref' - 'this' could be made 'final' ReganI vie for making 'this' a 'ref'
Jul 30 2007