C & C++

C & C++

Made by DeepSource

Redundant access specifiers CXX-C2012

Style
Minor
Autofix

Classes, structs, and unions containing redundant member (field and method) access specifiers can lead to code that is more difficult to read and maintain.

In the given code snippet, the access specifiers (public, protected, private) are repeated multiple times for the same set of members, which is unnecessary.

Removing the redundant access specifiers improves the code's readability and reduces unnecessary clutter.

Consider removing redundant access specifiers.

Bad Practice

class Foo {
public:
  int x;
  int y;
public: // redundant
  int z;
protected:
  int a;
protected: // redundant
  int b;
private:
  int c;
};

Recommended

class Foo {
public:
  int x;
  int y;
  int z;
protected:
  int a;
  int b;
private:
  int c;
}