I tried to have one static const member variable to relate to another static const variable in a class.
The motivation is that if I need to modify one value later (when coding), i don’t need to change all of those that are related to each other one by one.
For example:
class Box
{
public:
Box();
private:
static const double height = 10.0;
static const double lid_height = 0.5 + height;
};
It won’t compile and the error was ”Box::height’ cannot appear in a constant-expression’. So I guess you must type in the value of a static const member. But is there a way to have one member relate to another member variable of the same class, given that they will all be static const??
Set the value of your static const member variables outside of the class declaration, using the following syntax.