Lecture Notes for Introduction to Computer Science II
5 July 2001 - Scope
- names - what kind, type, scope
- consider
int i;
class c {
public:
int i;
int f(void) { int i; . . . }
}
int f(int i) { . . . }
- scope - lifetime, accessability, visibility
- lifetime - from birth to death; matters for the values contained
- accessability - from where in a program can a name be accessed
- visibility - a refinement on accessability; not considered further
- scopes are named after the constructs that delimit them - file, class,
function, block, statement scope
- file scope
- top-level entities
- function scope
- the function parameters and name
- block scope
- within curly brackets
- statement scope
- for statements
- can be confused with block scope
- class scope
- within classes - like a file scope
- controlling accessability
- why bother - simplify the name space
- within files -
extern
and static
- within classes - the
::
scope resolution operator
This page last modified on 5 July 2001.