As a side note: when you declare a class
, the scope is closed by default (opposite to struct
, where members are by default public.)
The member of the variable "x" is available only to your class and its friends. No one else can access the "x" directly (this can indirectly if you have a function that returns a link to it, which is a very bad idea.)
The text you are quoting indicates visibility for the compiler, so X::x
exists, no matter what. It will not disappear just because it is private. Visibility is used to find the member you are referring to, and the first match is returned. At this point, the compiler checks for availability, if it is available, you're fine. If not, it is poorly formed.
Notice that I mentioned friends. This keyword makes all member variables available. When the compiler deals with friends, it completely ignores all protected and private keywords.
In most cases, this is a very simple process. He's getting in order. Period.
Where it becomes more complicated, you start using virtual functions: they can be made public, protected and private, and this can change depending on the class declaration ... (A comes from B and makes a publicly protected virtual function, this is not at all a very good idea, but C ++ does not stop you from doing this.) Of course, this applies only to functions, and not to the elements of a variable, therefore another object.
Alexis wilke
source share