Simple code sample of Nesting Structures. I'm I doing something illegal here?

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 22 14:05:46 PST 2014


On Sat, Nov 22, 2014 at 11:54:01PM +0200, ketmar via Digitalmars-d-learn wrote:
> On Sat, 22 Nov 2014 20:57:05 +0000
> WhatMeWorry via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
> wrote:
> 
> >          auto bottom = NestedBottom(2, ['d','o','g']);
> ah, that good old thingy! there were some debates about locals that
> shadows fields and how that can introduce some hard-to-catch bugs.
> 
> you were hit by exactly that: you creating local variable `bottom`
> instead of assigning value to member `bottom`. that nasty little
> compiler is playing tricks with us all.

Yeah, this bit me before, and it was Not Fun. Generally, it's a very bad
idea to name local variables after field members due to shadowing. I'd
file a bug for it, but I'm not sure how likely it is to get fixed. But
you could try. ;-) (Sometimes it works. :-P)


T

-- 
Leather is waterproof.  Ever see a cow with an umbrella?


More information about the Digitalmars-d-learn mailing list