C++ Namespaces

Each time I’ve had to design a C++ application, I’ve come to wrestle myself with how to use namespaces. The best advice I got came from a page arguing about a specific feature of C++ namespaces, namely, using directives and declarations. In essence:

  • Quoting: «namespaces are designed to resolve name clashes, not to prevent them»
  • Never, ever, ever use using directives (using namespace std;) or using declarations (using std::cout;) inside an header file; use those only on cpp files, if you feel they’re useful
  • inside header files, always fully qualify the names, using namespace alias (namespace s=std;) if suitable

The details are very well explained in the article.


Os comentários estão fechados.