C & C++

C & C++

Made by DeepSource

Found the use of static member variable through class instance rather then class name CXX-C2022

Style
Minor

Accessing static member variables through class instances can give the impression that the member belongs to the instance, which is incorrect. This can lead to confusion and make the code harder to understand and maintain.

To fix this issue, simply replace the instance access with the class name followed by the member variable. This clearly indicates that the member is a static member of the class and avoids any confusion.

Bad practice

class MyClass {
public:
  static int myStaticVariable;
};

MyClass instance;
int value = instance.myStaticVariable;

Recommended

class MyClass {
public:
  static int myStaticVariable;
};

int value = MyClass::myStaticVariable;