access specifiers
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在class或struct身体的以下声明中定义的知名度
原文:
In a class or struct body define the visibility of following declarators
在继承列表,定义了最大的继承成员的可视性
原文:
In a inheritance list, define the maximum visibility of inherited members
[编辑] 语法
public: declarators | (1) | ||||||||
protected: declarators | (2) | ||||||||
private: declarators | (3) | ||||||||
class identifier : public class_name
|
(4) | ||||||||
class identifier : protected class_name
|
(5) | ||||||||
class identifier : private class_name
|
(6) | ||||||||
[编辑] 解释
#符号后宣派的说明公众更容易
原文:
# The symbols declared after the specifier have public accessibility
#符号后宣派的说明受保护的可访问性
原文:
# The symbols declared after the specifier have protected accessibility
#符号后宣派的说明具有私有可访问
原文:
# The symbols declared after the specifier have private accessibility
#继承的成员具有相同的可访问基类(保护或公共,私人将在派生类中是不可见的)
原文:
# The inherited members have the same accessibility as the base class ( either protected or public as private won't be visible in the derived class )
#继承的保护成员在派生类中的辅助功能
原文:
# The inherited members have protected accessibility in the derived class
#继承的成员在派生类中具有私有可访问
原文:
# The inherited members have private accessibility in the derived class
[编辑] 成员可访问性说明
;公开
- 公众成员的任何地方访问,内部和外部类的范围内原文:public members are accessible everywhere, within and outside the class scope
;保护
- 受保护的成员都可以访问内的类和方法,在其后代原文:protected members are accessible within the class and its methods and in its descendants
;私人
- 私有成员可以访问内的类和方法原文:private members can be only accessed within the class and its methods
要授予访问外部函数或类保护或私有成员,友谊的声明必须在类体内
原文:
To grant access to external functions or classes to protected or private members, a 友谊的声明 must be present in the class body
继承的私有成员仍然存在,但不能直接访问类中的数据
原文:
Inherited private members are still present in the class data but cannot be accessed directly
一个class默认私人的继承和成员的可访问性,struct,而不是默认的公共可访问性
原文:
A class has default private accessibility for inheritance and members, a struct has instead a default public accessibility
本章尚未完成 原因:example |