Namespace is used as additional information to differentiate between function.
Defines the context in which names are defined.
Syntax:
namespace namespace_name{
//codding
}
Access a namespace
access a namespace -enable entity
name::code;//code will be variable or function
The using directive
It tells the compiler that subsequent code is making use of names in specified name space.
Example--
// Creating namespaces
#include <iostream>
using namespace std;
namespace ns1
{
int value() { return 10; }
}
namespace ns2
{
double value() { return 0.5; }
}
using namespace ns1;
int main()
{
cout <<value() << '\n';
return 0;
}
No comments:
Post a Comment