Reputation: 55887
template<typename T>
class C
{
void f() { }
};
/*template<typename T>
void C<T*>::f() { }*/
template<>
void C<int*>::f() { }
If we remove comment, code will not compile. I know this (and i also know, that we should have partial specialization
for C<T*>
), but I cannot find words in standard, which explains such behaviour. I reread 14 par
of standard few times. Can you give me a quote or par of standard, that explains this?
EDIT.
template<typename T>
class C
{
template<typename U>
struct S { };
};
// #1
/*template<typename T>
class C<T*>
{
template<typename U>
struct S { };
};*/
// #2
/*template<typename T>
template<typename U>
struct C<T*>::S<U*> { };*/
template<>
template<typename U>
struct C<int*>::S<U*> { };
If we remove only comment next then #2 - code will not compile.
Upvotes: 1
Views: 312
Reputation: 477040
Here is the standard quote about what may be specialized expliclitly, from 14.7.3/1:
An explicit specialization of any of the following:
— function template
— class template
— member function of a class template
— static data member of a class template
— member class of a class template
— member enumeration of a class template
— member class template of a class or class template
— member function template of a class or class template
can be declared by a declaration introduced by
template<>;
Unless explicitly allowed, you cannot partially specialize anything, and member functions of class templates are not explicitly allowed. Only class templates may be specialized partially (as described in 14.5.5).
(Note that a member class template of an explicitly specialized class template is itself a class template.)
Upvotes: 1