digitalmars.D.bugs - access to outer scope variables
- J Anderson (32/32) May 01 2004 class B
-
Stewart Gordon
(9/38)
May 04 2004
- J Anderson (4/38) May 04 2004 Yeah I was confused to. Just run it and see.
- Walter (4/10) Mar 17 2005 Correct. I'll fix it.
- John Reimer (2/21) Mar 17 2005 Woah! That's scary, Walter. Are you /that/ far behind?! ;-)
class B { void load() { printf("val = %d\n", val); a.add(); } struct A { void add() { printf("val = %d\n", val); //Which val is this referring too? } } A a; int val; } int main (char[][] args) { B b = new B; b.load(); } Output: val = 0 val = 8719856 What is the second val referring to. If val is changed to static then things will work fine (for one class instance of course). Shouldn't this code be either: a) Disallowed at compile time or b) Have val refer to it's owner object's val (if that's possible). -- -Anderson: http://badmama.com.au/~anderson/
May 01 2004
J Anderson wrote:class B { void load() { printf("val = %d\n", val); a.add(); } struct A { void add() { printf("val = %d\n", val); //Which val is this referring too?The only one that's declared in your code.} } A a; int val; } int main (char[][] args) { B b = new B; b.load(); } Output: val = 0 val = 8719856<snip> That's very strange. Are you sure the code is all there? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
May 04 2004
Stewart Gordon wrote:J Anderson wrote:Yeah I was confused to. Just run it and see. -- -Anderson: http://badmama.com.au/~anderson/class B { void load() { printf("val = %d\n", val); a.add(); } struct A { void add() { printf("val = %d\n", val); //Which val is this referring too?The only one that's declared in your code.} } A a; int val; } int main (char[][] args) { B b = new B; b.load(); } Output: val = 0 val = 8719856<snip> That's very strange. Are you sure the code is all there? Stewart.
May 04 2004
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:c70jk9$off$1 digitaldaemon.com...What is the second val referring to. If val is changed to static then things will work fine (for one class instance of course). Shouldn't this code be either: a) Disallowed at compile time orCorrect. I'll fix it.b) Have val refer to it's owner object's val (if that's possible).That's Java <g>.
Mar 17 2005
Walter wrote:"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:c70jk9$off$1 digitaldaemon.com...Woah! That's scary, Walter. Are you /that/ far behind?! ;-)What is the second val referring to. If val is changed to static then things will work fine (for one class instance of course). Shouldn't this code be either: a) Disallowed at compile time orCorrect. I'll fix it.b) Have val refer to it's owner object's val (if that's possible).That's Java <g>.
Mar 17 2005