Item 31. Name Lookup and the Interface
Principle—Part 1
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()?
}
}
|