为什么在C ++中默认情况下数据成员是私有的? [英] Why are data members private by default in C++?

查看:73
本文介绍了为什么在C ++中默认情况下数据成员是私有的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,类中的所有数据成员默认情况下是否都是私有的?

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

推荐答案

因为更好被正确封装,只打开需要的东西,而不是默认打开所有东西,而不得不关闭它。

Because it's better to be properly encapsulated and only open up the things that are needed, as opposed to having everything open by default and having to close it.

封装(信息隐藏)是一种,并像安全性(例如,锁定网络服务)一样,默认值应该是好,而不是坏。

Encapsulation (information hiding) is a good thing and, like security (for example, the locking down of network services), the default should be towards good rather than bad.

这篇关于为什么在C ++中默认情况下数据成员是私有的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆