In C++, static method is called static member function.
A static member function can be called even if no objects of the class exist and the static function are accessed using only the class name and the scope resolution operator ::.
```
#include <iostream>
using namespace std;
class A {
private:
static int val;
public:
static void say() { cout << val << endl; }
void say2() { cout << val << endl; }
};
int A::val{1};
int main() {
A::say();
A a;
a.say2();
return 0;
}
#include <iostream>
using namespace std;
class A {
private:
static int val;
public:
static void say() { cout << val << endl; }
void say2() { cout << val << endl; }
};
int A::val{1};
int main() {
A::say();
A a;
a.say2();
return 0;
}
/*
1
1
*/
```