Creating and Using Namespaces 657
18
- Consider the following code:
int x = 4;
int main()
{
for( y = 1; y < 10; y++)
{
cout << y << “:” << endl;
{
int x = 10 * y;
cout << “X = “ << x << endl
}
}
// HERE
}
What is the value of Xwhen this program reaches “HERE” in the listing? - Can I use names defined in a namespace without using the usingkeyword?
- What are the major differences between normal and unnamed namespaces?
- What are the two forms of statements with the usingkeyword? What are the dif-
ferences between those two forms? - What are the unnamed namespaces? Why do we need unnamed namespaces?
- What is the standard namespace?
Exercises ........................................................................................................
1.BUG BUSTERS:What is wrong in this program?
0: #include <iostream>
1: int main()
2: {
3: cout << “Hello world!” << endl;
4: return 0;
5: }
- List three ways of fixing the problem found in Exercise 1.
- Show the code for declaring a namespace called MyStuff. This namespace should
contain a class called MyClass.