Jo**********@hotmail.com wrote:
Can anyone give me a simple work around to fix this compiler error on VC7.1
....cpp(23) : error C2912: explicit specialization; 'bool Equal<_F32>(const
_F32::type,const _F32::type)' is not a specialization of a function template
For this code:
template< class T >
inline bool Equal( const typename T::type v0,
const typename T::type v1 )
{
return v0 == v1;
}
template<>
inline bool Equal< _F32 >( const _F32::type v0, // error occurs at this line
const _F32::type v1 )
{
return fabs( v0 - v1 ) < _F32::epsilon;
}
EnderJSC
If you change 'typename T::type' in your main template it removes the
error and give a template function which is a lot easier to use ie:
template< class T >
inline bool Equal( const T v0,
const T v1 )
{
return v0 == v1;
}
template<>
inline bool Equal( const _F32::type v0,
const _F32::type v1 )
{
return fabs( v0 - v1 ) < _F32::epsilon;
}
Now the compiler can deduct the template type for most cases so you can
just write:
int a=1;
int b=2;
cout << Equal(a,b) << endl; // Uses general template
_F32::type c=1;
_F32::type d=2;
cout << Equal(c,d) << endl; // Uses specialization
PJakobse