2

I came across something odd with how a function name was resolved by the compiler when inside a namespace. Take this example:

namespace test {
  class Blah{};

  void good(Blah);
  void bad(int);
}

int main()
{
    good(test::Blah());
    bad(0);
    
    return 0;
}

I get the compile error main.cpp:11:5: error: ‘bad’ was not declared in this scope; did you mean ‘test::bad’?

I expected it to also fail to find good as well. Reading though the name lookup rules I can't find why this works.

Please explain why good is found but bad is not. Thank you.

bramp
  • 9,581
  • 5
  • 40
  • 46

0 Answers0