18.2.1. Namespace Definitions

A namespace definition begins with the keyword namespace followed by the namespace name. Following the namespace name is a sequence of declarations and definitions delimited by curly braces. Any declaration that can appear at global scope can be put into a namespace: classes, variables (with their initializations), functions (with their definitions), templates, and other namespaces:

namespace cplusplus_primer {    class Sales_data { / * ... * /};    Sales_data operator+(const Sales_data&,                         const Sales_data&);    class Query { /* ... */ };    class Query_base { /* ... */};} // like blocks, namespaces do not end with a semicolon

This code defines a namespace named cplusplus_primer with four members: ...

Get C++ Primer, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.