对C ++中成员的名称的访问控制 [英] Access control to names of members in C++

查看:133
本文介绍了对C ++中成员的名称的访问控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读Bjarne Stroustrup的程序设计语言时,有几个句子我无法获得感觉。下面的段落是关于对C ++中的类的成员的访问控制,例如private,protected,public。 粗体字是指一个特定的概念,我不知道是什么。

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.

推荐答案

我认为这是他的意思:

假设您有一个名为 p_member 私人成员。当然,它可以是数据成员方法常量 ...但在访问控制的上下文中, p_member 不起重要作用。重要的是,名为 p_member 的成员是私有的。无论是数据成员还是方法 - 它同样是私有的。

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.

这篇关于对C ++中成员的名称的访问控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆