variable shadow

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Black Ice

    variable shadow

    If any compiler will give warning when meed variable show.
    Following is the example code:
    void foo()
    {
    int total;
    if(...)
    {
    int total;
    ...
    }
    }


    --


    Regards,
    Black Ice

    Çë²»Òª»Ø¸´µ½ÎÒµ ÄÓÊÏä

    ×ÔÓÉ£¨liberty£© Î޷ǾÍÊÇÕâÑùÒ»Ö Ö³Ðŵ£ºÃ¿¸öÈ˽« »áµÃµ½Ò»ÖÖ±£ÕÏ£ ¬±£ÕÏÎÒÃÇ¿ÉÒÔÓë
    ȨÍþ¡¢¶àÊý¡¢Á÷Ë ×¼°ÓßÂÛµÄÓ°ÏìÏà ¿¹ºâ¡£





  • Victor Bazarov

    #2
    Re: variable shadow

    "Black Ice" <smartnoho@yaho o.com> wrote...[color=blue]
    > If any compiler will give warning when meed variable show.[/color]

    I am not sure I understand that sentence. 'Meed' is a noun. Used
    with another noun ('variable') it becomes an attribute. "Meed
    variable" is "earned reward variable"?... I don't understand.
    [color=blue]
    > Following is the example code:
    > void foo()
    > {
    > int total;
    > if(...)
    > {
    > int total;
    > ...
    > }
    > }[/color]

    No, in most cases no warning will be given. Name hiding (that's
    the C++ term) is a legal C++ construct and used often.

    Victor


    Comment

    • Victor Bazarov

      #3
      Re: variable shadow

      "Black Ice" <smartnoho@yaho o.com> wrote...[color=blue]
      > If any compiler will give warning when meed variable show.[/color]

      I am not sure I understand that sentence. 'Meed' is a noun. Used
      with another noun ('variable') it becomes an attribute. "Meed
      variable" is "earned reward variable"?... I don't understand.
      [color=blue]
      > Following is the example code:
      > void foo()
      > {
      > int total;
      > if(...)
      > {
      > int total;
      > ...
      > }
      > }[/color]

      No, in most cases no warning will be given. Name hiding (that's
      the C++ term) is a legal C++ construct and used often.

      Victor


      Comment

      Working...