xxxxxxxxxx
#include <iostream>
using namespace std;
namespace square{
int x;
int y;
}
int main(){
using namespace square;
x = 10;
y = 0;
cout << x << y << endl;
}
xxxxxxxxxx
A namespace is a declarative region that provides a scope to the
identifiers (the names of types, functions, variables, etc) inside
it. Namespaces are used to organize code into logical groups and to
prevent name collisions that can occur especially when your code base
includes multiple libraries
xxxxxxxxxx
//using namespaces
using namespace std;
//creating namespaces
namespace custom{
class example{
public:
static int method(){
return 0;
}
};
};
//using custom namespaces
using namespace custom;
xxxxxxxxxx
#include <iostream>
using namespace std;
int main() {
cout<< "Hello World" ;
}
//If you are a web developer, please give https://code.ionicbyte.com/ a try
xxxxxxxxxx
//Namespaces provide a method for preventing name conflicts in large projects.
//Symbols declared inside a namespace block are placed in a named scope that
//prevents them from being mistaken for identically-named symbols in other
//scopes. Multiple namespace blocks with the same name are allowed.
//All declarations within those blocks are declared in the named scope.
namespace yourName{
//any code you want to put inside
}
xxxxxxxxxx
Namespaces avoids name collisions bacause of large libraray in c++.
This feature was not supported in C
xxxxxxxxxx
namespace Q
{
namespace V // V is a member of Q, and is fully defined within Q
{ // namespace Q::V { // C++17 alternative to the lines above
class C { void m(); }; // C is a member of V and is fully defined within V
// C::m is only declared
void f(); // f is a member of V, but is only declared here
}
}