"Joseph Turian" <tu****@gmail.c om> wrote in message
news:11******** *************@u 72g2000cwu.goog legroups.com
XH*****@gmail.c om wrote: i also do not know how to writer this functions
but this way is simple:
I know this method too.
However, I have a bunch of these functions and it would be unwieldly
to put them in the class declaration.
Hence, I would like to know the syntax for having the implementation
outside.
Joseph
template<typena me T>
class bar {
template<typena me A, typename B>
void f(){}
template<>
f<int, unsigned>() { }
};
V
VC++ allows you to do this for some backward compatibility reason, but it is
non-standard. According to the standard, you can only specialize member
templates at namespace scope, i.e., outside the class declaration.
Further, you can only specialize member templates if the enclosing class is
fully specialized. What you are trying to do --- specialize a member
template while leaving the enclosing class un-specialized --- is simply not
allowed by the standard.
Relevant sections from the standard are as follows:
Section 14.7.3/18:
"In an explicit specialization declaration for a member of a class template
or a member template that appears in namespace scope, the member template
and some of its enclosing class templates may remain unspecialized, except
that the declaration shall not explicitly specialize a class member template
if its enclosing class templates are not explicitly specialized as well."
You may note that this refers to specializations that appear in namespace
scope. Section 14.7.3/2 makes it clear that this is the only option:
"An explicit specialization shall be declared in the namespace of which the
template is a member, or, for member templates, in the namespace of which
the enclosing class or enclosing class template is a member."
--
John Carson