Can Someone explain to me in detail what namespace is?
Can Someone explain to me in detail what namespace is?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
ex. namespace [identifier] { namespace-body }
A namespace declaration identifies and assigns a name to a declarative region.
The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.
The declarative region of a namespace declaration is its namespace-body.
I hope this helps some!
I presume you are wondering why people include the line:
using namespace std;
In simple terms, use it to avoid name collisions. Basically when you are dealing with many header files some may contain variable names that conflic with other variable names. It is difficult to keep track of all these variables. Including this creates a separate namespace area for variable names.
#include <iostream>
using namespace std;
namespace cheese {
int x = 5;
};
namespace Poop {
int x = cheese::x * 2;
}
int main(void) {
int x = Poop::x + 5;
cout << "X is " << x << endl;
return 0;
}