Member variable in C++ class that is always constant for all objects of that class?
- by user1799323
I'm constructing a class where I have three member variables that I want to always be the same value NO MATTER WHAT.
I have
class foo{
public:
double var_1, var_2, var_3;
double x=1, y=2, z=3;
[functions go here]
};
that gave me an error since I can't initialize a variable like that. But I want x, y and z to always be 1, 2 and 3 respectively. I tried defining them outside the class but that doesn't work since I want them to be member variables of the class.
How do I do this?