Item 34. Name Lookup and the Interface
Principle—Part 4
Difficulty: 9
We conclude this
miniseries by considering some implications of the Interface
Principle on name lookup. Can you spot the (quite subtle) problem
lurking in the following code?
-
What is name
hiding? Show how it can affect the visibility of base class names
in derived classes.
-
Will the
following example compile correctly? Make your answer as complete
as you can. Try to isolate and explain any areas of doubt.
// Example 2: Will this compile?
//
// In some library header:
namespace N { class C {}; }
int operator+(int i, N::C) { return i+1; }
// A mainline to exercise it:
#include <numeric>
int main()
{
N::C a[10];
std::accumulate(a, a+10, 0);
}
|