Rule 11-0-1 and protected members

Moderators: david ward, misra cpp

Post Reply
Posts: 1
Joined: Thu Jun 29, 2017 10:15 am

Rule 11-0-1 and protected members

Post by tw39124 » Mon Jul 03, 2017 3:42 pm

Rule 11-0-1 says that "Member data in non-POD class types shall be private" and the example clarifies that both "public" and "protected" members violate this rule. The rationale says "the implementation retains more control over how the object state can be modified".

I fail to see how protected members diminish the "control" over the object state that the implementation has. Can someone explain in more detail why protected member variables specifically are disallowed? A subtype has an "is-a" relationship with the base type, after all, so I don't see why it shouldn't benefit from inheriting the base type's member variables.

misra cpp
Posts: 161
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Rule 11-0-1 and protected members

Post by misra cpp » Wed Jul 12, 2017 2:17 pm

It encourages strong partitioning and data hiding.

We will consider adding an exception for abstract classes in the next version
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.11 Member access control (C++)”