Error: shadowing declaration is deprecated

jicman jic at mail.com
Sun Dec 24 22:02:11 PST 2006


Sorry, didn-t read the other posts.  ignore this post.


== Quote from %u (jic at mail.com)'s article
> == Quote from Ary Manzana (ary at 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


More information about the Digitalmars-d-learn mailing list