[ fromfile: scopestorage.xml id: scopes ]
Every identifier has a scope which is determined by where it was declared. The scope of an identifier in a program is the region(s) of the program within which it can be used. Using a name outside of its scope is an error.
The same name may declared/used in different scopes. Ambiguities are resolved as follows:
The name from the most local scope is used.
If the name is not defined in the most local scope, the same name defined in the nearest enclosing scope will be used.
If the name is not defined in any enclosing scope, then the compiler will report an error.
There are five possible scopes in C++.
Block scope (local to a block of statements)
Function scope (the entire extent of a function) [55]
Class scope (the entire extent of a class, including its member functions)
File scope (the entire extent of a source code file)
Global scope (the entire extent of a program)
Because the compiler only deals with one source file at a time, only the linker can tell the difference between global and file scope, as Example 20.3 shows.
| Generated: $Date: 2009-09-08 12:15:32 -0400 (Tue, 08 Sep 2009) $ | © 2009 Alan Ezust and Paul Ezust. |