53 lines
1.3 KiB
Plaintext
53 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The difference between ``++private++`` and ``++protected++`` visibility is that child classes can see and use ``++protected++`` members but cannot see ``++private++`` ones. Since a ``++final++`` class will have no children, marking the members of a ``++final++`` class ``++protected++`` is confusingly pointless.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
class C final {
|
|
protected: // Noncompliant
|
|
void fun();
|
|
};
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp,diff-id=1,diff-type=compliant]
|
|
----
|
|
class C final {
|
|
private:
|
|
void fun();
|
|
};
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
When overriding a base class function, keeping the same visibility as for the base class is standard practice. This rule ignores ``++protected++`` functions in a ``++final++`` class that override base class ``++protected++`` functions.
|
|
|
|
== Resources
|
|
|
|
* {cpp} reference - https://en.cppreference.com/w/cpp/language/final[final specifier]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Get rid of this "protected" specifier and make visibility of the following members "private".
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|