My compiler error:
main.cpp:11:5: error: call to function 'foo' that is neither visible in the template definition nor found by argument-dependent lookup foo(T()); ^ main.cpp:18:5: note: in instantiation of function template specialization 'quux<n::A>' requested here quux<n::A>();
This makes it clear what the problem is.
Note void foo(int) does not make it work; it's just a bug / extension in your compiler.
You mentioned that you cannot define void foo(n::A) before quux() , however, when you say in comments that you cannot define it in the n namespace, the reasons you give do not seem to apply. This should solve the problem without the other problems you mentioned.
template<typename T> void quux() { foo(T()); } namespace n { void foo(n::A) {} } using n::foo;
If you cannot transfer the definition of void foo(n::A) to where it works with the correct two-phase search (again, before quux() or inside the n namespace), there is a kind of hacker solution that may work for you: forward declare the correct overload of foo() inside quux() .
template<typename T> void quux() { void foo(T); foo(T()); }
Ultimately, the function must be defined inside the same namespace as quux() , and it must conform to the declaration of the 'generic' forward.
Or another alternative. It was quite recently that most C ++ compilers started offering the correct two-phase name lookup, so there is a lot of code that is not correct, but which compilers want to support. If you cannot change your code, this may be a good candidate for including the compatibility compiler option; my compiler accepts the -fdelayed-template-parsing flag to disable the search for two-phase names and instead always searches for names in the creation context.
bames53
source share