Function Lookup in Namespaces

Function Lookup in Namespaces - Function Lookup in...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Function Lookup in Namespaces Jonathan Schilling, jls@sco.com An important change has recently been made in the way functions are found within namespaces. The three basic ways of making the contents of a namespace visible were discussed in C++ Newsletters #002 and #004. These are: explicit qualification, using directives, and using declarations. Consider the following namespace, which declares a class and some (non-member) functions: namespace N { class A { . .. }; A& operator+(const A&, const A&); void f(A); void g(); } Now consider the following function that takes arguments of the class type: void z(N::A x, N::A y) { x + y; // (1) f(x); // (2) g(); // (3) } Given the original rules for namespaces (just the three basic methods of namespace visibility), all three of the statements in this function are compilation errors, because none of the functions being called are visible. However the standards committee has changed the way functions are looked up. Now there is a new language rule, which says that the namespaces of the classes of the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

Function Lookup in Namespaces - Function Lookup in...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online