In the code below, it looks quite obvious that the function definition for myFn
with two arguments should come from namespace N
. But the compiler fails to compile it. Is it a compiler (g++ 8.3) limitation, or imposed by the C++ standard?
#include <bits/stdc++.h>
using namespace std;
namespace N
{
// Same name function exists in class A
void myFn(int a, int b)
{
cout << a << ' ' << b << endl;
}
}
using namespace N;
class A {
public:
void myFn(int a)
{
#ifdef FINE
// Explicitly specify where should myFn definition come from
N::myFn(a, a);
#else
myFn(a, a);
#endif
}
};
int main()
{
A a;
a.myFn(3);
return 2;
}