全部书籍

专业

应用 关于 Coach 登录 开始阅读

书籍暂未推出简体中文版——当前显示英文版。

Computer Science · 术语表

什么是 Namespace?

Definition 1.2 University Computer Science — Year 2 · 第 1 章 — From C to C++: Classes and Resource Management

A namespace is a named region of declarations. A name n declared in the namespace ns is written ns::n outside it, so that two libraries may both declare an area without a clash. The standard library declares everything in the namespace std.

示例

Example 1.3 (Following the references)

The line int &r = x; makes r a second name of x, so r = 10 sets x to 10. In swap_ints(x, y), the parameters a and b are bound to x and y themselves: the function exchanges the caller’s values and main prints x = 2, y = 10. The two area calls go to two different functions, 3×33 \times 3 and 2×4.52 \times 4.5, both 9. In total_length, the parameter const std::vector<std::string> &words reads the caller’s vector without copying its four strings, whose lengths 9+12+14+79 + 12 + 14 + 7 make 42.

在原文中阅读 →