Todos os livros

Profissional

Apps Sobre Coach Entrar Começar a ler

Computer Science · Glossário

O que é Namespace?

Definition 1.2 University Computer Science — Year 2 · Capítulo 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.

Exemplos

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.

Ler no capítulo →