static Members
static members belong to the class and are shared by all objects.
Example
#include <iostream>
struct Counter { static inline int n = 0; Counter() { ++n; } };
int main() {
Counter a, b;
std::cout << Counter::n << "\n";
return 0;
}Result
2
Exercise
Shared member.
int n;Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.