C++

Topic: Templates

What is namespace?

Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say<br>it somehow, they serve to split the global scope in sub-scopes known<br>as namespaces.<br><br>The form to use namespaces is:<br><br>namespace identifier { namespace-body }<br><br>Where identifier is any valid identifier and namespace-body is the set of classes, objects and<br>functions that are included within the namespace. For example:<br><br>namespace general { int a, b; } In this case, a and b are normal variables integrated within the<br>general namespace. In order to access to these variables from outside the namespace we have to<br>use the scope operator ::. For example, to access the previous variables we would have to put:<br><br>general::a general::b<br><br>The functionality of namespaces is specially useful in case that there is a possibility that a global<br>object or function can have the same name than another one, causing a redefinition error.

Browse random answers: