I want to reshoot a question based on the answer and appending discussion of:
Why is a non static data member reference not a variable?:
A non-static data member of class doesn't create a new variable itself, it just helps you to define the properties of the class. If it did create a new variable, you'd be able to write code like this:
class Chamber {
public:
int pot;
};
void f(bool b) {
if (b)
Chamber::pot = 2;
}
What would that even mean? Would it find every instance of Chamber and set all their pots to 2? It's a nonsense.
However, in the current n4296 c++17 draft a variable is still definened as (§3.6
):
A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name, if any, denotes the reference or object.
The argumentation in the accepted answer seems logical to me but it is, based on my understanding of the variable-definition above, conflicting with the standard.
Question Are non-static non-reference data member declarations variables, and if yes, why are they considered to be so since I cannot use them in an intuitive fashion ( as e.g. Chamber::pot
from the example in the answer ) ?