M
Michael Stembera
I have a case of a very simple template class w/ a
template method. If I define a specialization of the
method outside the body of the template class it does not
compile. Here is a tiny example to illustrate.
template<typename T>
class C
{
public:
template<int N> bool foo(void);
template<> bool foo<1>(void);
};
template<typename T>
template<int N>
bool C<T>::foo(void)
{
return N > 0;
}
template<typename T>
template<>
bool C<T>::foo<1>(void)
{
return false;
}
// error C2768: 'C<T>::foo' : illegal use of explicit
template arguments
However, if I define the specialization inside
template<typename T>
class C
{
public:
template<int N> bool foo(void)
{
return N > 0;
}
template<> bool foo<1>(void)
{
return false;
}
};
it compiles fine. BTW, the non specialized version can
be defined inside or outside of the class and it makes no
difference either way. Also, if the class itself is NOT
a template class both versions compile fine.
Is this a user or compiler or C++ standard issue? I'm
using MS VC++ 7.1.3088.
Thanks in advance,
Michael Stembera
template method. If I define a specialization of the
method outside the body of the template class it does not
compile. Here is a tiny example to illustrate.
template<typename T>
class C
{
public:
template<int N> bool foo(void);
template<> bool foo<1>(void);
};
template<typename T>
template<int N>
bool C<T>::foo(void)
{
return N > 0;
}
template<typename T>
template<>
bool C<T>::foo<1>(void)
{
return false;
}
// error C2768: 'C<T>::foo' : illegal use of explicit
template arguments
However, if I define the specialization inside
template<typename T>
class C
{
public:
template<int N> bool foo(void)
{
return N > 0;
}
template<> bool foo<1>(void)
{
return false;
}
};
it compiles fine. BTW, the non specialized version can
be defined inside or outside of the class and it makes no
difference either way. Also, if the class itself is NOT
a template class both versions compile fine.
Is this a user or compiler or C++ standard issue? I'm
using MS VC++ 7.1.3088.
Thanks in advance,
Michael Stembera