在 C++ 中,为什么类成员的默认可见性是私有的,而结构是公共的?
In C++, why is private the default visibility for members of classes, but public for structs?
C++ 是作为 C 的超集引入的.结构是从 C 继承而来的,其成员的语义是公共的.存在大量 C 代码,包括希望与 C++ 一起使用的库,它们使用结构.类是在 C++ 中引入的,为了符合 OO 的封装哲学,它们的成员默认是私有的.
C++ was introduced as a superset of C. Structs were carried over from C, where the semantics of their members was that of public. A whole lot of C code exists, including libraries that were desired to work with C++ as well, that use structs. Classes were introduced in C++, and to conform with the OO philosophy of encapsulation, their members are private by default.
这篇关于C++ 类/结构成员的默认可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!