Every name defined in a given scope must be unique within that scope. This can be difficult for large complex applications as name collisions become an issue.
Namespaces may be defined at global scope or inside another namespace. They may not be defined inside a function or a class.
The entities defined inside a namespace are called namespace members:


namespace namespace_name
{	...
}

Names defined in a namespace may be accessed directly by other members of the namespace. Code outside the namespace must indicate the namespace in which the name is defined, e.g.:

	namespace_name::some_member q = namespace_name::some_funtion();

A namespace can be defined in several parts and can therefore be spread out over several files. This means you can use it in the header file declarations and in the associated .cc file.

Using namespace


	std::cout	//:: is the the scope operator and that we want to use the name 'cout' that is
			//defined in the namespace 'std'.

To avoid having to specify the namespace (the library) every time we want to use a method we can use the following:


	using namespace::name

Once the using declaration have been made we can use name directly without refering to its namespace:-


	using std::string;

int main()
{
	string s;
	...
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *