Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

While reading The C++ Programming Language by Bjarne Stroustrup, there's a few sentences that i have trouble getting a sense of. The paragraph, which is right below, is about access control to members of a class in C++ such as private, protected, public. The bold words are referring to a specific concept, which i have no idea what that is.

The access control is applied uniformly to names. What a name refers to does not affect the control of its use. This means that we can have private member functions, types, constants, etc., as well as private data members.

My best assumption is that "What a name refers to" stands for an object in raw memory, which ultimately means that we can take a pointer to an object entity of private member in raw memory, and access it regardless of access control. However, it seems to be wrong considering that it has nothing to do with the statement that we can have private members. I have no idea what the paragraph above tries to convey.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
146 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think this is what he meant:

Let's say you have a private member named p_member. Of course, it can be a data member, a method, a constant... but in the context of access control, the nature of p_member does not play a significant role. What is important is that the member named p_member is private. Doesn't matter if it's a data member or a method - it is equally private.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...