Exceptional C++[Bug]?
- by gautam kumar
I have been reading Exceptional C++ by Herb Sutter. On reaching Item 32
I found the following
namespace A
{
struct X;
struct Y;
void f( int );
void g( X );
}
namespace B
{
void f( int i )
{
f( i ); // which f()?
}
}
This f() calls itself, with infinite recursion. The reason is that the only visible f() is B::f() itself.
There is another function with signature f(int), namely the one in namespace A. If B had written "using namespace A;" or "using A::f;", then A::f(int) would have been visible as a candidate when looking up f(int), and the f(i) call would have been ambiguous between A::f(int) and B::f(int). Since B did not bring A::f(int) into scope, however, only B::f(int) can be considered, so the call unambiguously resolves to B::f(int).
But when I did the following..
namespace A
{
struct X;
struct Y;
void f( int );
void g( X );
}
namespace B
{
using namespace A;
void f( int i )
{
f( i ); // No error, why?
}
}
That means Herb Sutter has got it all wrong? If not why dont I get an error?