explicit specialization in non-namespace scope

Alexandre Oliva oliva@dcc.unicamp.br
Tue Sep 22 06:35:00 GMT 1998


Nathan Myers <ncm@cygnus.com> writes:

>> >     An explicit specialization of a member
>> >     function, member class or static data member of a class template
>> >     shall be declared in the namespace of which the class template
>> >     is a member.  */

> It's still not clear that the above text applies to the case mentioned.
> "In the namespace of which the enclosing class is a member" is satisified
> both outside and inside the class.  When it means to say "not in a class 
> or in a block", it says "at namespace scope" or sometimes "in namespace 
> scope"

> Anyhow, all is not lost.  You can specialize this member anyway,
> even in egcs with bug added, just not as cleanly as you wanted:

>   struct A {
>     template <int I> inline int factorial();
>   };
>   template <> inline int A::f<0>() { return 1; }
>   template <int I> inline void A::f<I>() { return f<I-1>() * I; }

Unfortunately, this won't work if A is a template class, because,
AFAIK, in order to specialize A<...>::factorial<I>, A<...> must be
fully specialized.

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil




More information about the Gcc mailing list