On Jun 21, 9:15*pm, huil...@gmail.com wrote:
For example, like in the following, the part commented out was
intended as partial spectialzation, but it would even compile. *Is it
even legal to partially specialize a nested template class inside
another template class?
template < typename T >
struct A
{
* * * * template < typename U >
* * * * struct B
* * * * {
* * * * * * * * static const int v = 1;
* * * * };
/* * * *template < // this doesn't compile
* * * * struct B < int >
* * * * {
* * * * * * * * static const int v = 3;
* * * * };
*/
};
Yes, it is possible to partially specialize a nested class template in
C++ (without having to specialize the enclosing class template). It is
not legal however to explicitly specialize a nested class template (if
the enclosing class template is not explicitly specialized as well).
In fact, the example program demonstrates this last point by defining
a B<intexplicit specialization - without explicitly specializing A
as well.
In other words, the problem with the above program is that B<intis
not a partial specialization - but a complete specialization of B.
Greg