1#include <iostream>
2
3using namespace std;
4
5namespace {
6int x;
7void display();
8}
9
10namespace{
11void display(){
12cout << "x is "<<x<<endl;
13}
14}
15
16int main()
17{
18 x = 25;
19 display();
20 return 0;
21}
22
23
1// namespaces
2#include <iostream>
3using namespace std;
4
5namespace foo
6{
7 int value() { return 5; }
8}
9
10namespace bar
11{
12 const double pi = 3.1416;
13 double value() { return 2*pi; }
14}
15
16int main () {
17 cout << foo::value() << '\n';
18 cout << bar::value() << '\n';
19 cout << bar::pi << '\n';
20 return 0;
21}
1namespace Parent
2{
3 inline namespace new_ns
4 {
5 template <typename T>
6 struct C
7 {
8 T member;
9 };
10 }
11 template<>
12 class C<int> {};
13}
14
1//Header.h
2#include <string>
3
4namespace Test
5{
6 namespace old_ns
7 {
8 std::string Func() { return std::string("Hello from old"); }
9 }
10
11 inline namespace new_ns
12 {
13 std::string Func() { return std::string("Hello from new"); }
14 }
15}
16
17#include "header.h"
18#include <string>
19#include <iostream>
20
21int main()
22{
23 using namespace Test;
24 using namespace std;
25
26 string s = Func();
27 std::cout << s << std::endl; // "Hello from new"
28 return 0;
29}
30