I wonder why the following snipped of C++ code compiles without error:
namespace ns {
struct foo {};
void stuff(void*x) {}
}
int main() {
ns::foo x;
stuff(&x);
}
I thought that it must be obligatory to put a namespace qualifier in front of stuff
, and indeed if I replace the variable x with int x
, then the error arises. It appears that the compiler deduces the namespace to which stuff
belongs from the type of its argument, which doesn't make sense to me. Tested with GCC 4.2.1 and 4.8.3