default visibility of C++ class/struct members

S I picture S I · Aug 8, 2009 · Viewed 62.9k times · Source

In C++, why is private the default visibility for members of classes, but public for structs?

Answer

Oren Trutner picture Oren Trutner · Aug 8, 2009

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.