Scope rules

Discussion in 'C++' started by n2xssvv g02gfr12930, Jul 20, 2006.

  1. Although I rarely if ever have a problem with scope, I was wondering
    whether anybody knows of good reference, (book, web page, etc), that
    covers scope rules. Hopefully this will be helpful to others.

    JB
     
    n2xssvv g02gfr12930, Jul 20, 2006
    #1
    1. Advertising

  2. n2xssvv g02gfr12930 wrote:
    > Although I rarely if ever have a problem with scope, I was wondering
    > whether anybody knows of good reference, (book, web page, etc), that
    > covers scope rules. Hopefully this will be helpful to others.


    You mean like "Always keep the scope of the name as tight as possible"?
    Or do you mean like "overloading only relates to functions in the same
    scope" and the related "derived class scope is tighter than the base
    class scope (and included in it)"?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jul 20, 2006
    #2
    1. Advertising

  3. n2xssvv g02gfr12930 posted:


    > Although I rarely if ever have a problem with scope, I was wondering
    > whether anybody knows of good reference, (book, web page, etc), that
    > covers scope rules. Hopefully this will be helpful to others.



    A rule of thumb would be:

    An object exists from the point of its definition, until the next
    closing brace. (Unless it's static of course).


    If you define an object within a "for" loop as follows:

    for(int i;;) {}


    Then its scope is as if you wrote:

    {
    int i;

    for(;;) {}

    }


    --

    Frederick Gotham
     
    Frederick Gotham, Jul 20, 2006
    #3
  4. Victor Bazarov wrote:
    >
    > You mean like "Always keep the scope of the name as tight as possible"?
    > Or do you mean like "overloading only relates to functions in the same
    > scope" and the related "derived class scope is tighter than the base
    > class scope (and included in it)"?
    >
    > V


    All of those points would be nice, with examples demonstrating the how
    and the why. Perhaps I should create some web pages on scope covering
    class, namespace, code scope, and any others you'd like to suggest.
    Thanks for your response, and no doubt you could think of countless
    examples.

    JB
     
    n2xssvv g02gfr12930, Jul 20, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?=22J=2EJ=2EGarc=EDa=22?=

    Special scope rules for static operators?

    =?ISO-8859-1?Q?=22J=2EJ=2EGarc=EDa=22?=, May 29, 2005, in forum: C++
    Replies:
    4
    Views:
    432
    =?UTF-8?B?IkouSi5HYXJjw61hIg==?=
    May 29, 2005
  2. Kevin Spencer

    Re: QUERY: 'On Error Resume Next' scope rules

    Kevin Spencer, Jun 17, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    586
    Kevin Spencer
    Jun 17, 2006
  3. Andrew Collier

    scope rules in nested functions

    Andrew Collier, Jan 29, 2005, in forum: Python
    Replies:
    0
    Views:
    302
    Andrew Collier
    Jan 29, 2005
  4. fctk

    Scope Rules

    fctk, Apr 16, 2006, in forum: C Programming
    Replies:
    3
    Views:
    462
  5. Scope rules

    , Sep 14, 2005, in forum: C++
    Replies:
    3
    Views:
    462
    red floyd
    Sep 15, 2005
Loading...

Share This Page