November 1999
Intermediate to advanced
240 pages
5h 22m
English
Difficulty: 9½
When you call a function, which function do you call? The answer is determined by name lookup, but you're almost certain to find some of the details surprising.
In the following code, which functions are called? Why? Analyze the implications.
namespace A
{
struct X;
struct Y;
void f( int );
void g( X );
}
namespace B
{
void f( int i )
{
f( i ); // which f()?
}
void g( A::X x )
{
g( x ); // which g()?
}
void h( A::Y y )
{
h( y ); // which h()?
}
}
Two of the three cases are (fairly) obvious, but the third requires a good knowledge of C++'s name lookup rules—in particular, ...
Read now
Unlock full access