explicit instantiation of '<namespace>::<templated class>' must occur in namespace '<namespace>' (C++)
Go Up to Compiler Errors And Warnings (C++) Index
You can see this error if you try to compile the following with a Clang-enhanced compiler:
namespace N {
template<typename T>
class TTest
{
};
}
using namespace N;
template class TTest<int>;
- Note: Even though gcc accepts the snippet of code shown above without objection, it seems that Clang is right here; the other compilers have not yet caught up with the standard changes (see: Bug 60786).
This is Clang implementing Defect Report #275. As mentioned in DR275, the core issue is:
> "An explicit instantiation shall appear in an enclosing namespace of its template.
> If the name declared in the explicit instantiation is an unqualified name, the
> explicit instantiation shall appear in the namespace where its template is declared."
The workaround is to use the qualified name, as in:
namespace N {
template<typename T>
class TTest
{
};
}
//using namespace N;
template class N::TTest<int>;