Why are data members private by default in C++?

后端 未结 5 1201
挽巷
挽巷 2021-02-06 01:23

Is there any particular reason that all data members in a class are private by default in C++?

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 02:08

    In a word, encapsulation. The goal is to have private implementation details (such as data members) be private. Only explicitly public API is made available to clients of the class.

提交回复
热议问题