What is namespace?

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

Showing Answers 1 - 3 of 3 Answers

sabir

  • Jan 13th, 2006
 

it heichiyal order of the class where it developed to over come the drawback of ambiuity of header file system.data.sqlclient is the eg for the same here system -----> is the root name space data-----------> is a class sqlclient ------->is a deveied class syntaxnamespace sabs class ds ''''''' the class def''''end class end namespace

  Was this answer useful?  Yes

saroj

  • Oct 31st, 2007
 

Minimize name collision in the global name space, this  namespace keyword assining a distinict name to a libray to use the same indentifier names without creating any name collision further name more the  compiler uses the namespce signature for differenting the defn.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions