J
Juha Nieminen
I'm wondering why this seems to be illegal C++:
namespace Hops { template<bool> void foo(); }
template<> void Hops::foo<false>() { std::cout << "false\n"; }
template<> void Hops::foo<true>() { std::cout << "true\n"; }
Both gcc and clang give errors, saying that the template specializations
are in a "different namespace" than the template declaration.
(Yes, I know that the problem can be solved by putting the
specializations explicitly inside the namespace. However, this seems
to be an odd special rule. Compilers do not seem to have any problem
in compiling this if you enable a proper extension. Why does this rule
exist?)
namespace Hops { template<bool> void foo(); }
template<> void Hops::foo<false>() { std::cout << "false\n"; }
template<> void Hops::foo<true>() { std::cout << "true\n"; }
Both gcc and clang give errors, saying that the template specializations
are in a "different namespace" than the template declaration.
(Yes, I know that the problem can be solved by putting the
specializations explicitly inside the namespace. However, this seems
to be an odd special rule. Compilers do not seem to have any problem
in compiling this if you enable a proper extension. Why does this rule
exist?)