AUTOSAR C++14 Rule A11-0-2
A type defined as struct shall: (1) provide only public data members, (2) not provide any special member functions or methods, (3) not be a base of another struct or class, (4) not inherit from another struct or class
Since R2020a
Description
Rule Definition
A type defined as struct shall: (1) provide only public data members, (2) not provide any special member functions or methods, (3) not be a base of another struct or class, (4) not inherit from another struct or class.
Rationale
The items prohibited by this rule are not supported for struct
types
in C code. In C++, a struct
type can have private data members, member
functions, be inherited and inherit from other struct
-s or
class
-es. However, a developer typically associates these features with
a class
type. Adhering to this rule makes sure that you use only classes
to implement object oriented concepts such as data encapsulation and inheritance.
Adhering to this rule also makes sure that your struct
types conform
to the rules of Plain Old Data (POD) types and can be exchanged with C code.
Polyspace Implementation
The checker flags struct
types with one or more of these features:
Contains private or protected data members.
struct
members are public by default.Contains member functions.
Acts as base class for another
struct
orclass
, or inherits from anotherstruct
orclass
.
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, Automated |
Version History
Introduced in R2020a