| Lecture 3 - Slide 22 : 27|
Logical program organization
Namespaces are used for the logical program organization of C++ programs
- A namespace is a named scope
- Use of names requires namespace qualification, with use of the scope resolution operator ::
- A using declaration can be used to add a name (an alias) to a local scope (such as a function) from a namespace
- using N::name;
- name is declared/defined as a local synonym to N::name
- A using directive allows convenient access to names from a given namespace
- using namespace N;
- Can - and should - be used locally, in a function for instance
Illustration of using declarations and using directives - by example.
Compilable variant of the program from above.
Names declared in a namespace - natively or by using declarations - take priority over names brought in via using directives