模板的用法,看看是什么问题
template <class T>
// min of a,b; nan if either a or b are nan
inline T min(T a, T b)
{
return (a < b) ? a : b;
}
template <>
inline rsip_float32 min<rsip_float32>(rsip_float32 a, rsip_float32 b)
{
if (rsip::isnan(a)||rsip::isnan(b))
{
return rsip::nan();
}
else
{
return (a < b) ? a : b;
}
}
template <>
inline rsip_float64 min<rsip_float64>(rsip_float64 a, rsip_float64 b)
{
if (rsip::isnan(a)||rsip::isnan(b))
{
return rsip::nan();
}
else
{
return (a < b) ? a : b;
}
}
错误提示
e:\RSIP_prj\RSIP\base\h\rsipcommon.h(181) : error C2027: use of undefined type 'T'
e:\RSIP_prj\RSIP\base\h\rsipcommon.h(181) : error C2226: syntax error : unexpected type 'T'
e:\RSIP_prj\RSIP\base\h\rsipcommon.h(181) : error C2146: syntax error : missing ')' before identifier 'b'
e:\RSIP_prj\RSIP\base\h\rsipcommon.h(181) : error C2146: syntax error : missing ';' before identifier 'b'
e:\RSIP_prj\RSIP\base\h\rsipcommon.h(181) : error C2059: syntax error : ')'
e:\RSIP_prj\RSIP\base\h\rsipcommon.h(181) : error C2059: syntax error : ')'
e:\RSIP_prj\RSIP\base\h\rsipcommon.h(197) : error C2912: explicit specialization; 'rsip_float32 rsip::min<rsip_float32>(rsip_float32,rsip_float32)' is not a specialization of a function template
e:\RSIP_prj\RSIP\base\h\rsipcommon.h(197) : fatal error C1903: unable to recover from previous error(s); stopping compilation