December 25, 2006 Re: Error: shadowing declaration is deprecated | ||||
---|---|---|---|---|
| ||||
Posted in reply to %u | Sorry, didn-t read the other posts. ignore this post. == Quote from %u (jic@mail.com)'s article > == Quote from Ary Manzana (ary@esperanto.org.ar)'s article > > jicman escribió: > > > == Quote from Bill Baxter's article > > >> jicman wrote: > > >>> Greetings! > > >>> > > >>> this code, > > >>> > > >>> foreach(char[] u; FPUsers) > > >>> { > > >>> > > >>> } > > >>> > > >>> results in, > > >>> > > >>> Error: shadowing declaration jic.libs.FPSDK.FindUser.u is > > > deprecated. > > >>> Will anyone explain this to me? I tried to do a search on it, > > > but I couldn't > > >>> anything related to this. Found other integer arrays, but > > > nothing about > > >>> char[]. Any help would be greatly appreciated. Thanks. > > >>> > > >>> jos� > > >> It means you have another variable named 'u' in the same > function > > >> declared somewhere before that foreach loop. The theory is that > > > many > > >> times these are bugs, and when they are they can be hard to > spot. > > >> I'm not totally enamored with the feature myself, since I don't > > > recall > > >> ever really been bitten by it, but I have happily shadowed > > > variables in > > >> the past when it suited me. Especially little dummy > > > counter/placeholder > > >> variables like your 'c' above. > > >> But anyway, that's what the error means. Just rename 'c' to c2 > or > > > cc or d. > > >> --bb > > > > > > Ok, I'll buy that, but this is not working either: > > > > > > char[] u; > > > foreach(u; FPUsers) > > > { > > > } > > > > > > That should work. > > But probably in your code there is some other variable "u" defined, > > previous to the "char[] u" line. Check that. > > Cheers, > > Ary > Ok, let's take a look at this small program: > void main() > { > char[][] tArr = null; > tArr.length = tArr.length + 1; > tArr[0] = "hi"; > char[] u; > foreach(u;tArr) > printf(u); > } > As you can see, there are no other declaration of u in the program, > and here is what I get when I use dmd: > 0:56:01.67>dmd test.d > test.d(7): Error: shadowing declaration test.main.u is deprecated > Ok, what is it that I am not understanding. Sorr |
Copyright © 1999-2021 by the D Language Foundation