Skip to content

Latest commit

 

History

History
53 lines (42 loc) · 5.04 KB

CppNamespace.md

File metadata and controls

53 lines (42 loc) · 5.04 KB

namespace is a keyword to group functions and classes.

To call something from a certain namespace, write the namespace's name in front, followed by the scope operator, ::.

Functions and classes that are not put into a namespace reside in the global namespace.

The default namespace used is the global namespace. You can change this by using the keyword using.

All STL functions and classes are in the namespace std.

  • [1] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 14.5. Advice. page 417: '[1] Use namespaces to express logical structure'
  • [2] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 14.5. Advice. page 417: '[2] Place every nonlocal name, except main(), in some namespace'
  • [3] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 14.5. Advice. page 417: '[3] Design a namespace so that you can conveniently us it without accidentally gaining access to unrelated namespaces'
  • [4] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 14.5. Advice. page 417: '[4] Avoid very short names for namespaces'
  • [5] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 14.5. Advice. page 417: '[5] If necessary, use namespace aliases to abbreviate long namespace names'
  • [6] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 14.5. Advice. page 417: '[6] Avoid placing heavy notational burdens on users of your namespaces'
  • [7] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 14.5. Advice. page 417: '[7] Use seperate namespaces for interfaces and implementations'
  • [8] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 14.5. Advice. page 417: '[8] Use the Namespace::member notation when defining namespace members'
  • [9] Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Item 57: 'Keep a type and its nonmember function interface in the same namespace'
  • [10] Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Item 58: 'Keep types and functions in seperate namespaces unless they're specifically intended to work together'
  • [11] Herb Sutter, Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. 2005. ISBN: 0-32-111358-6. Item 59: 'Don't write namespace usings in a header file or before an #include'
  • [12] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 18.5. Advice. page 548: '[7] Use namespaces to associate helper functions with "their" class'
  • [13] Jason Turner, cppbestpractices: Always Use Namespaces