Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: All
Oct 9, 1998

The Rationale Behind Namespaces

Some users consider the addition of namespaces to C++ as superfluous or even harmful. In order to understand why namespaces were added to the language, imagine that the file system on your PC / Mainframe didn't have any directories and subdirectories. All files would be stored in a flat repository, which would be visible to every user and application at all times. Consequently, you would run into extreme difficulties. Filenames would clash (with some systems limiting a filename to 8 characters + 3 for the extension, this is likely to happen); simple actions like listing, copying or searching files would be much more difficult; and security and authorization restrictions would be severely compromised.

Namespaces in C++ are equivalent to directories. They can be nested easily, they protect you from name clashes, they allow you to hide declarations simply by not using a namespace, and they do not incur any runtime or memory overhead.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date