Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Misra C++ 2023 14.1.1: clarify inherited members
#1
Hi everybody,

how should rule 14.1.1 handle inherited members, especially given the extra comment regarding "privileged access to data members".

For instance, consider
Code:
struct Base {
  int bm;
};

class Derived final : private Base {
private:
  int dm;
};

"Base" only has a single public member, thus is compliant.
"Derived" has a private member "dm" directly and another private member "bm" by inheritance. This is compliant I think.

However, what about public inheritance:
Code:
class Derived final2 : public Base {
private:
  int dm;
};

My assumption is that this now has a public and a private member and is thus non-compliant.

Can you please clarify:
- Are inherited members treated like non-inherited ones, taking into account the kind of inheritance?
- Does the additional note regarding derived classes requiring privileged acccess only refer to the discouraged usage of "protected" or should it enforce private members in class "Base" in case some derived class uses the member (ie. to avoid having to rely on private inheritance)?

Thanks for your help, regards

Sebastian
Reply


Messages In This Thread
Misra C++ 2023 14.1.1: clarify inherited members - by sks - 03-11-2025, 10:48 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)