Conditional summary of access control for C++ class
- 2020-05-19 05:16:10
- OfStack
Summary of conditions for access control of C++ class
Recently, when I was using C++ to create a class, I suddenly found that I didn't fully understand the functions of class access control public, protected and private. Later, I looked up some information, which is recorded here.
Access control
The important properties of the C++ class are encapsulation and inheritance. Therefore, the most critical issue is the issue of access. public, protected and private control access rights.
public | protected | private | |
---|---|---|---|
类成员是否可以访问 | Yes | Yes | Yes |
友元函数是否可以访问 | Yes | Yes | Yes |
子类是否可以访问 | Yes | Yes | No |
类的实例化对象是否可以访问 | Yes | No | No |
inheritance
Permission changes caused by three inheritance methods:
public | protected | private | |
---|---|---|---|
public继承 | public | protected | private |
protected继承 | protected | protected | private |
private继承 | private | private | private |
Thank you for reading, I hope to help you, thank you for your support of this site!