Namespace in C++ programming is a collection of related name or identifier i.e. functions, class, and variables which helps to separate these identifiers from similar.
#include<iostream.h>
#include<conio.h>
namespace first_space //'first_space' is name of Name Space.
{
void func()
{
cout<<"Inside first_space"<<endl;
}
}
namespace second_space //'second_space' is name of Name Space.
{
void func()
{
cout<<"Inside second_space"<<endl;
}
}
void main()
{
first_space::func(); //Calls function'func()' from first name space.
second_space::func(); //Calls function'func()' from second name space.
getch();
}
#include<iostream.h>
#include<conio.h>
namespace first_space
{
void func()
{
cout<<"Inside first_space"<<endl;
}
}
namespace second_space
{
void func()
{
cout<<"Inside second_space"<<endl;
}
}
using namespace first_space; //using 'first_space' Name Space here.
void main()
{
func(); //This calls function from first name space.
getch();
}
#include<iostream.h>
#include<conio.h>
namespace first_space
{
void func()
{
cout<<"Inside first_space"<<endl;
}
namespace second_space
{
void func()
{
cout<<"Inside second_space"<<endl;
}
}
}
using namespace first_space::second_space;
void main()
{
func(); //This calls function from second name space.
getch();
}