C & C++

C & C++

Made by DeepSource

Found unnecessary member initialization CXX-C2026

Anti-pattern
Minor

Member variables in a class are automatically initialized to their default values when an object of the class is created. Explicitly initializing them to the same default values is redundant and can clutter the code, making it harder to read and maintain.

To fix this issue, remove the unnecessary member initializations. This will make the code cleaner and more concise.

Bad practice

class Example {
  int a;
  float b;
  std::string c;

  public:
  Example(): a{0}, b{0.0}, c{""} {}
};

Recommended

class Example {
  int a;
  float b;
  std::string c;
};