Static or non-static getters / setters for a variable of a static class in C ++

Suppose I have the following class:

class A {
private:
    static double X;
};

double A::X = 0.0;

The variable A::Xreally needs to be static, because all instances Amust use the same value in the context in which I deal A::X.

Now, my question is whether to do getter and setter functions for A::Xstatic. They will be defined as follows:

void A::setValue(const double x) {
#pragma omp critical
{
    if(x<0.0||x>1.0)
        // custom macro call to raise exception

    X = x;
}
}

double A::getValue() {
#pragma omp critical
{
    return X;
}
}

It seems to me that it has absolutely no practical significance whether these functions getter and setter are added to Aas static or non-static member functions. Is it correct?

, , , getter setter , ?

+4
2
  • ,
  • : getA, , A
+5

. /getter, , . , .

, ; , , , . , .

+2

All Articles