-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11(iii). Unnamed namespace
95 lines (90 loc) · 1.16 KB
/
11(iii). Unnamed namespace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//Program for illustrate the Unnamed namespace
#include<iostream>
using namespace std;
namespace
{
int a=19;
namespace
{
int b=20;
namespace
{
int c=30;
namespace
{
int d=40;
}
}
}
}
void display()
{
cout<<"namespace1: "<<a<<endl;
cout<<"namespace2: "<<b<<endl;
cout<<"namespace3: "<<c<<endl;
cout<<"namespace4: "<<d<<endl;
}
int main()
{
display();
return 0;
}
/* //for better result please remove the /* and 8? and try yourself
#include<iostream>
using namespace std;
namespace
{
int a=10;
}
namespace
{
int b=20;
}
namespace
{
int c=40;
}
void display()
{
cout<<"namespace1: "<<a<<endl;
}
void dsplay()
{
cout<<"namespace2: "<<b<<endl;
}
void diapl()
{
cout<<"Namespace3: "<<c<<endl;
}
int main()
{
display();
dsplay();
diapl();
return 0;
}
*/
//explicit qualification
/* remove this /* and */ for compile
#include<iostream>
using namespace std;
int i=9;
namespace A
{
int a=22,b=44,c=55;
namespace B
{
int i=10,j=20,k=30;
}
}
int main()
{
cout<<A::a++;
cout<<"\n";
cout<<A::B::i++;
cout<<"\n";
cout<<::i++; //global
return 0;
}
//we are invoking the global namespace using scope resolution without preciding qualifier
*/