对于类成员函数的本地 POD:
有什么理由更喜欢static const int ONE = 1;或const int ONE = 1吗?
有什么理由更喜欢static const float HALF = (float)0.5;或const float HALF = (float)0.5。
例如f在课堂上的功能A
#ifdef SP
#define float REAL
#else
#define double REAL
#endif
double
A::f(const REAL x)
{
static const REAL HALF = (REAL)0.5;
return max(x, HALF);
}
or
double
A::f(const REAL x)
{
const REAL HALF = (REAL)0.5;
return max(x, HALF);
}
or
double
A::f(const REAL x)
{
const REAL HALF = 0.5f;
return max(x, HALF);
}