[Link]
Identify the Basic Differences Between C and C++
Uses of Multiple Namespaces
A programmer who uses several independently developed libraries may encounter naming clashes by accident. Suppose that library A
defines a global variable called listCount and library B also defines a global variable called listCount. If the developer attempts
to use both libraries A and B at the same time, it can lead to problems. The compiler will complain that listCount is defined more than
once at the application level. This problem can be solved by using multiple namespaces.
Additional namespaces may be created using the namespace keyword. The use of multiple namespaces for the conflicting libraries
allows a developer to easily segregate variable names and thus avoid conflicts.
An example is:
namespace LibraryA {
int listCount;
}
namespace LibraryB {
int listCount;
}
The example above shows two snippets of code, defining separate namespaces LibraryA, and LibraryB and a variable
listCount within each.
A subsequent using declaration brings the variable in a given namespace into the current scope, or visibility, of your application
(without fear of conflict), as shown below:
using LibraryA::listCount;
ListCount = 25;
1 of 1 3/11/2011 10:15 AM