Rule 10-3-1

Moderators: david ward, misra cpp

Post Reply
wcarl
Posts: 1
Joined: Mon Aug 12, 2013 5:16 pm
Company: Ultra Electronics - Flightline Systems

Rule 10-3-1

Post by wcarl » Fri Jan 17, 2014 4:48 pm

There shall be no more than one definition of each virtual function on each path through the inheritance hierarchy.

If I'm interpreting this rule correctly, once you define a virtual function for a derived class with the virtual base class as an ancestor, no more derivations in the chain can override the first definition.

This would seem to cripple a key advantage of using classes and an object-oriented design.

Isn't it pretty common to override a virtual member function in a child class even if the parent class has provided a different definition? Please explain.

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

Re: Rule 10-3-1

Post by misra cpp » Mon Oct 05, 2015 3:06 pm

This is intentional and, as stated in the text for the rule, is done to increase clarity for review and maintenance. It would be acceptable to deviate if a more complex hierarchy is required.

We will review this when working on the next version of MISRA C++.
Posted by and on behalf of
the MISRA C++ Working Group

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 10-3-1

Post by dg1980 » Wed Nov 15, 2017 2:39 pm

Under the impression of MISRA Compliance i came up with two deviation permits so far:
  • Reliability (Fault tolerance): Implementing default/fallback behaviour/strategy for polymorphic types
  • Maintainability (Reusability): Extending base class functionality for polymorphic types

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

Re: Rule 10-3-1

Post by misra cpp » Wed Jan 17, 2018 4:46 pm

Thanks
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.10 Derived classes (C++)”