D - assigning to 'this'
- Carlos Santander B. (20/20) Jul 07 2003 Why does an assignation to 'this' doesn't work?
- Patrick Down (5/33) Jul 07 2003 but
-
Carlos Santander B.
(19/19)
Jul 07 2003
"Patrick Down"
escribió en el mensaje - Patrick Down (6/17) Jul 07 2003 Actually that was stupid of me. The issue is that you are not
- DeadCow (5/9) Jul 14 2003 "this" must be kind of "read only" and produce error on assignement, lik...
Why does an assignation to 'this' doesn't work? class A { int a; void assign(A tmp) { this=tmp; } //This line } void main() { A a1= new A(),a2=new A(); a1.a=4; a2.a=5; a1.assign(a2); printf('%d %d'\n,a1.a,a2.a); } Instead of "5 5", it outputs "4 5". I know you might find this weird, but I'd like to know the reasoning behind it. ------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.497 / Virus Database: 296 - Release Date: 2003-07-04
Jul 07 2003
"Carlos Santander B." <carlos8294 msn.com> wrote in news:bed76p$1lsp$1 digitaldaemon.com:Why does an assignation to 'this' doesn't work? class A { int a; void assign(A tmp) { this=tmp; } //This line } void main() { A a1= new A(),a2=new A(); a1.a=4; a2.a=5; a1.assign(a2); printf('%d %d'\n,a1.a,a2.a); } Instead of "5 5", it outputs "4 5". I know you might find this weird,butI'd like to know the reasoning behind it.Try this. void assign(inout A tmp) { this=tmp; } //This line------------------------- Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.497 / Virus Database: 296 - Release Date: 2003-07-04
Jul 07 2003
"Patrick Down" <pat codemoon.com> escribió en el mensaje news:Xns93B1D6772AD29patcodemooncom 63.105.9.61... | "Carlos Santander B." <carlos8294 msn.com> wrote in news:bed76p$1lsp$1 | digitaldaemon.com: | | > Why does an assignation to 'this' doesn't work? | > | | Try this. | | void assign(inout A tmp) { this=tmp; } //This line | Same result. ————————————————————————— Carlos Santander --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.497 / Virus Database: 296 - Release Date: 2003-07-04
Jul 07 2003
"Carlos Santander B." <carlos8294 msn.com> wrote in news:bedbq5$1qb1$1 digitaldaemon.com:"Patrick Down" <pat codemoon.com> escribió en el mensaje news:Xns93B1D6772AD29patcodemooncom 63.105.9.61... | "Carlos Santander B." <carlos8294 msn.com> wrote in news:bed76p$1lsp$1 | digitaldaemon.com: | | > Why does an assignation to 'this' doesn't work? | > | | Try this. | | void assign(inout A tmp) { this=tmp; } //This lineActually that was stupid of me. The issue is that you are not changing the object that a1 is pointing to. "this" is like a local parameter to a functionchangeing it only chages it for the scope of the functions.
Jul 07 2003
"Patrick Down" <pat codemoon.com> a écrit dans le message news: Xns93B1E340F1A6Cpatcodemooncom 63.105.9.61...Actually that was stupid of me. The issue is that you are not changing the object that a1 is pointing to. "this" is like a local parameter to a functionchangeing it only chages it for the scope of the functions."this" must be kind of "read only" and produce error on assignement, like ".size" property of object. -- Nicolas Repiquet
Jul 14 2003