Lecture Notes for Introduction to Computer Science II

5 July 2001 - Scope


  1. names - what kind, type, scope

  2. consider

    int i;
    
    class c {
      public:
        int i;
        int f(void) { int i; . . . }
      }
    
    int f(int i) { . . . }
    

  3. scope - lifetime, accessability, visibility

    1. lifetime - from birth to death; matters for the values contained

    2. accessability - from where in a program can a name be accessed

    3. visibility - a refinement on accessability; not considered further

  4. scopes are named after the constructs that delimit them - file, class, function, block, statement scope

  5. file scope

    1. top-level entities

  6. function scope

    1. the function parameters and name

  7. block scope

    1. within curly brackets

  8. statement scope

    1. for statements

    2. can be confused with block scope

  9. class scope

    1. within classes - like a file scope

  10. controlling accessability

    1. why bother - simplify the name space

    2. within files - extern and static

    3. within classes - the :: scope resolution operator


This page last modified on 5 July 2001.