Redundant access specifiers should be removed because they needlessly clutter the code.


== Noncompliant Code Example

----
struct S {
  public: // Noncompliant; does not affect any declaration
  private:
    void method();
  private: // Noncompliant; does not change accessibility level
    int member;
  private: // Noncompliant; does not affect any declaration
};
class C {
    int member;
  private: // Noncompliant;  does not change accessibility level
    void method();
};
----


== Compliant Solution

----
struct S {
  private:
    void method();
    int member;
};
class C {
    int member;
    void method();
};
----


== Exceptions

An access specifier at the very beginning of a ``++class++`` or ``++struct++`` that matches the default access level is ignored even when it doesn't change any accessibility levels.

----
class C {
  private: // redundant but accepted
    // ...
};
struct S {
  public: // redundant but accepted
    // ...
};
----
Such a specifier is redundant, but ignored to allow ``++class++``es and ``++struct++``s to be described uniformly.

----
class C {
  public:
    void call();

  protected:
    int delete();

  private:
    int code;
};
struct S {
  public: // redundant but accepted
    int sum();

  protected:
    int min();

  private:
    int count;
};
----


ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
