我一直在阅读Herb Shutter的“Exceptional C++”,其中的“条款1:#define或const和内联”。
据说类内初始化只允许对于整型(整数,字符,布尔值)以及常量进行。
我想知道为什么双精度/浮点数不能在类声明中初始化。是否有特定的原因?
class EngineeringConstants { // this goes in the class
private: // header file
static const double FUDGE_FACTOR;
...
};
// this goes in the class implementation file
const double EngineeringConstants::FUDGE_FACTOR = 1.35;
我想知道为什么下面的声明不被允许:。
class EngineeringConstants { // this goes in the class
private: // header file
static const double FUDGE_FACTOR = 1.35;
...
};
?