Is it members of a class template specialization, described in 14.5.4.3 ?
"Murrgon" <murrgon@hotmail.com> wrote in message
news:u7uIlOPhGHA.2188@TK2MSFTNGP04.phx.gbl...
Okay I can't get this to compile:
//
===========================================================================
#include <math.h>
template<typename NUMTYPE> class NumPair
{
public:
NUMTYPE x, y;
NumPair(NUMTYPE xVal = 0, NUMTYPE = yVal) : x(xVal), y(yVal)
{
}
// Generic IsZero()
bool IsZero() const
{
return 0 == x && 0 == y;
}
// Specialized IsZero() for float types
bool IsZero<float>() const
{
return 0.000001f >= abs(x) && 0.000001f >= abs(y);
}
IsZero isn't a template and can't be specialized - it's an ordinary member
of a template class (there's a difference!). To specialize IsZero you
need to specialize the entire class.
};
//
===========================================================================
however it works if I pull the specialized version of IsZero() outside
of the class definition like this:
template<> bool NumPair<float>::IsZero() const
{
return 0.000001f >= abs(x) && 0.000001f >= abs(y);
}
This shouldn't compile either - IsZero is not a template and cannot be
specialized. What compiler are you using?
Is there some way to specify the syntax to get the first example to
compile,
or am I stuck using the method outside the scope of the class definition?
Neither of the approaches you've posted is valid C++ code. I'd suggest
moving IsZero outside the class, making an ordinary template function and
a non-template overload for float types (and perhaps another for double).
-cd