GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 20 of 203    Print  
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.


  
Total Answers and Comments: 3 Last Update: December 07, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 13, 2006 08:06:50   #1  
sabir        

RE: What is namespace?
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
 
Is this answer useful? Yes | No
October 31, 2007 01:14:41   #2  
saroj        

RE: What is namespace?
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.
 
Is this answer useful? Yes | No
December 07, 2008 12:28:26   #3  
burraganesh Member Since: December 2008   Contribution: 20    

RE: What is namespace?
Namespace is simply a name given to a global space to form a sub-space in global space.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape