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.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести