NR.7: Don't make all data members protected
NR.7:不要将所有数据成员的访问权限设为保护
Reason(原因)
protected data is a source of errors. protected data can be manipulated from an unbounded amount of code in various places. protected data is the class hierarchy equivalent to global data.
保护类型的数据成员是错误的来源。受保护的数据可以在各个地方被无限多代码来操纵。受保护的数据是等效于全局数据的类层次结构。
Example(示例)
代码语言:javascript复制???
Alternative(其他选项)
- Make member data public or (preferably) private 将成员数据公开或(最好)私有
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nr7-dont-make-all-data-members-protected