Member variable in C++ class that is always constant for all objects of that class?

Posted by user1799323 on Stack Overflow See other posts from Stack Overflow or by user1799323
Published on 2012-11-17T22:44:20Z Indexed on 2012/11/17 23:00 UTC
Read the original article Hit count: 177

Filed under:

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?

© Stack Overflow or respective owner

Related posts about c++