A static member is a member whose lifetime is bound to the class and not to any object. Static members are shared copies between all instances of the class. They can be accessed with the scope resolution operator (::) on the class or dot operator (.) on the object:

class Shape {
public:
  static int count;
};

int Shape::count = 0;

int main() {
  Shape s;
  Shape::count++;  // 1
  s.count++;       // 2
}

A static non-const member variable must be defined once outside the class and cannot be initialised inside the class:

class Shape {
public:
  static int count = 0;  // ERROR.
};

Static members defined outside the class must omit the static keyword:

int Shape::count = 0;         // OK.
static int Shape::count = 0;  // ERROR.

A static member function can be called without an object. It can access static members but not the fields of any object since it has no this pointer:

class Shape {
public:
  static int get_count() { return count; }  // OK.
  static int count;

  static int get_sides() { return sides; }  // ERROR.
  int sides;
};

int Shape::count = 0;

A static constexpr member can be initialised inside the class, which is the usual way to define a class-level constant:

class Shape {
public:
  static constexpr int MAX_SIDES = 12;
};

int limit = Shape::MAX_SIDES;

inline lets a static member be initialised inside the class, without a separate definition outside it:

class Shape {
public:
  static inline int count = 0;
};

References