rspec/rules/S5965/cfamily/rule.adoc

39 lines
842 B
Plaintext

== Why is this an issue?
When specifying base classes for a class, the access level is private by default. While private inheritance has its uses, it is far less used than public inheritance. Therefore:
* Either you want public inheritance, and you have to specify it
* Or you want private inheritance, and you should be explicit about this design decision, by specifying it too.
=== Noncompliant code example
[source,cpp]
----
class B {
};
class C : B {
};
----
=== Compliant solution
[source,cpp]
----
class B {
};
class C : private B { // Or public, if it was private by mistake
};
----
== Resources
=== Related rules
* S5966 is a similar rule that deals with base visibility in structs
* S3540 is another rule that favors a different coding style for base classes. It should not be activated at the same time as this rule.