MISRA C++:2008 Rule 11-0-1
Member data in non- POD class types shall be private
Description
Rule Definition
Member data in non- POD class types shall be private.
Rationale
If classes have data members that are publicly accessible, other classes and functions might interact with the class data members directly. Any change in the class might require updating the clients that use the class. If a class is not a plain-old-data (POD) type, restricting access to its data members enables encapsulation of the class. In such an encapsulated class, the implementation details of the class are opaque to the clients that use it. The class retains control over its implementation and can be maintained independently without impacting the clients that use the class.
Polyspace Implementation
Polyspace® flags nonprivate data members in classes that are not POD types. Polyspace space uses the same definition of POD classes as the standard.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Member Access Control |
Category: Required |