-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameSpace.cpp
More file actions
46 lines (36 loc) · 775 Bytes
/
Copy pathNameSpace.cpp
File metadata and controls
46 lines (36 loc) · 775 Bytes
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
//namespace group of header files
//namespace : declaration of variables ,functions,classes and more
#include <iostream>
using namespace std;
//create a namespace
namespace myspace
{
int a;
void fun();
class A
{
public:
void function1();
};
}
//defining function of namespace
void myspace::fun()
{
cout<<"This is from fun."<<endl;
}
//defining function of namespace of class
void myspace::A::function1()
{
cout<<" This is from class A"<<endl;
}
using namespace myspace; //using our namespace
int main(int argc, char const *argv[])
{
//myspace::a=5; //accessing variables after declaration
a = 10; //this is from myspace
cout<<"a is "<<a<<endl;
A a1;
a1.function1();
fun();
return 0;
}