A namespace is similar to a class in object oriented programming. A namespace contains functions defined by the programmer. for example namespace std contains functions like cout and cin.
namespaces can be globaly declared like so: "using namespace std;"
which includes all the functions located in the namespace std.
if you only need to use cout you can globaly declare only cout like this "using std::cout;"
or
std::cout<<"calling cout directly from namespace std";
you can make your own namespaces as well
namespace mynamespace;
void myfunction(){
code for function
}
and use it
using mynamespace::myfunction;
The main use of a namespace is to reduce or eliminate collisions with names that may be duplicated but have different functionality. For example, I may want to use an object with the name of 'cout', but that name already exists. If I place it in a different namespace I would be able to use it with that name.
Copyright © 2026 eLLeNow.com All Rights Reserved.