Alex Rivera | Logout

Why and how should I use namespaces in C++?

Asked 2010-11-18T05:02:12.497
37

I have never used namespaces for my code before. (Other than for using STL functions)

  1. Other than for avoiding name conflicts, is there any other reason to use namespaces?
  2. Do I have to enclose both declarations and definitions in namespace scope?
Edit
Report

1 Answer

17

Here is a good reason (apart from the obvious stated by you).

Since namespace can be discontiguous and spread across translation units, they can also be used to separate interface from implementation details.

Definitions of names in a namespace can be provided either in the same namespace or in any of the enclosing namespaces (with fully qualified names).

answered 2010-11-18T05:04:36.897

Your Answer