Which will print the following code:
#include <iostream>

using namespace std;

namespace NA
{
  struct A {
    A() : a(1) {}
    int a;
  };

  void f(A &b)
  {
    cout << b.a << endl;
  }
}

NA::A a;

void f(NA::A &b) 
{
  cout << b.a*2 << endl;
}

int main()
{
  f(a);
  return 0;
}
Explanation
According to the König search rule (Koenig lookup), if the function parameter is a class object, the function search is performed in the namespace of this class along with the standard scope. Thus, there are two identical signatures, which leads to ambiguity and compilation error, as a consequence.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes