gpt4 book ai didi

c++ - 为什么数据成员在 C++ 中默认是私有(private)的?

转载 作者:可可西里 更新时间:2023-11-01 16:52:16 27 4
gpt4 key购买 nike

在 C++ 中类中的所有数据成员在默认情况下都是私有(private)的是否有任何特殊原因?

最佳答案

The Design and Evolution of C++

2.10 保护模型

Before starting work on C with Classes, I worked with operating systems. The notions of protection from the Cambridge CAP computer and similar systems - rather than any work in programming languages - inspired the C++ protection mechanisms. The class is the unit of protection and the fundamental rule is that you cannot grant yourself access to a class; only the declarations placed in the class declaration (supposedly by its owner) can grant access. By default, all information is private.

关于c++ - 为什么数据成员在 C++ 中默认是私有(private)的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2532107/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com