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
説明
ルール定義
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.
根拠
このルールによって禁止される項目は、C コード内の struct 型でサポートされません。C++ では、struct 型は、プライベート データ メンバーとメンバー関数をもつことができ、他の struct または class から継承されたり、それらを継承したりできます。ただし、開発者の多くは、これらの機能を class 型に関連付けます。このルールに従うことによって、クラスのみを使用してデータのカプセル化や継承などのオブジェクト指向の概念を実装します。
また、このルールに従うことによって、struct 型は、Plain Old Data (POD) 型のルールに従い、C コードと交換できるようになります。
Polyspace 実装
チェッカーは、以下の機能の 1 つ以上を備えた struct 型にフラグを設定します。
プライベートまたは保護されたデータ メンバーを含む。
structメンバーは既定でパブリックです。メンバー関数を含む。
他の
structまたはclassの基底クラスとして機能するか、他のstructまたはclassから継承する。
トラブルシューティング
ルール違反が想定されるものの、Polyspace® から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。
例
チェック情報
| グループ: メンバー アクセス制御 |
| カテゴリ: Required、Automated |
バージョン履歴
R2020a で導入