条款28: 划分全局名字空间
namespace 作为前缀,防止不同名字域的类型、常量等互相污染。
没命名的名字空间一般用于限制名字空间内部元素的可见性。
namespace sdm {const double book_version = 2.0;class handle { ... };handle& gethandle();
}
早期用struct模拟namespace,不推荐。
// 用于模拟名字空间的一个结构的定义
struct sdm {static const double book_version;class handle { ... };static handle& gethandle();
};
const double sdm::book_version = 2.0;