Why explicit instantiation of outer class template is required before explicit instantiation of a class template
My question is w.r.t the following thread : specialize a me开发者_如何学JAVAmber template without specializing its parent
I'm absolutely fine with the standard saying that it is illegal to do so. But i want to understand why is it illegal to do so? What would be impact had it been allowed?
Maybe because of something like this:
template <typename T>
struct foo
{
template <typename U>
struct bar
{
typedef U type;
};
};
template <typename T>
struct foo<T>::bar<int> // imaginary
{
typedef void type;
};
template <>
struct foo<float>
{
template <typename U>
struct bar
{
typedef U* type;
};
};
// is it void [foo<T>::bar<int>] or
// int* [foo<float>::bar<U>]?
typedef foo<float>::bar<int>::type ambiguous;
A sensible solution is to say "we'll make the entire thing explicit".
精彩评论