I don't understand why C++ allows only integral types and enum (enum is an integral type too) to be defined within a class declaration. Whereas all other types, including float point types (i.e. double and float), have to be defined outside the class declaration. Clearly the must be a reason for this, but I can't figure it out.
Code example:
#include <iostream>
using namespace std;
struct Node {
static const int c = 0; // Legal Definition
static const long l = 0l; // Legal Definition
static const short s = 0; // Legal Definition
static const float f = 0.0f; // Illegal definition
static const string S = "Test"; // Illegal definition
static const string JOB_TYPE; // Legal declaration
static const float f; // Legal declaration
static const double d; // Legal declaration
};
const string Node::JOB_TYPE = "Test"; // correct definition
const float Node::f = 0.0f; // correct definition
const double Node::d = 0.0; // correct definition
int main() {
cout << Node::c << endl;
cout << Node::c << endl;
cout << Node::JOB_TYPE << endl;
cout << Node::f << endl;
}