I got a very annoying issue with C++ and function name resolution. consider the following code:
#include <iostream>
namespace A {
class STA{ int i; };
void func(STA a) {std::cout << "Namespace A\n";}
}
namespace B {
void func(A::STA a) {std::cout << "Namespace B\n";}
}
int main(int argc, char **argv)
{
A::STA aaa;
func(aaa); // will compile and print out: Namespace A, I would love a compiler error
return 0;
}
Looks like compiler check the function parameter and decide that according to those parameters it does know the function so no need to add A:: or B::
the problem here is that this code will compile. meaning to use func from namespace B I have to force B::func(aaaa). This is source of bug. I want to know if there is a way to force the compiler you refuse to compile if I am not explicit with the namespace. I was debugging a big project and I couldn't understand where was the problem. I accidentality discovered that the wrong function was call.