I don't know what you mean by "static class".
In C++ you can have static members or functions in a class. These are not bound to any instance but instead are "class global".
Definition:
class C
{
public:
static int a;
static void f() {cout << a << "\n";}
void m() {cout << a << "\n";}// normal method
};
int C::a = 21;
class C
{
public:
static int a;
static void f() {cout << a << "\n";}
void m() {cout << a << "\n";}// normal method
};
int C::a = 21;
To copy to clipboard, switch view to plain text mode
Usage:
C c1, c2;
cout << c1.a << " " << c2.a << "\n";// normal way to access
c1.a = 42;
cout << C::a << "\n";// static access
C::f();// static access
c1.f(); c2.f();
C::a = 21;
c1.g(); c2.g();
C c1, c2;
cout << c1.a << " " << c2.a << "\n";// normal way to access
c1.a = 42;
cout << C::a << "\n";// static access
C::f();// static access
c1.f(); c2.f();
C::a = 21;
c1.g(); c2.g();
To copy to clipboard, switch view to plain text mode
And there's another meaning of static when refering to variables in implementation files: These variables are file-local when declared static.
Bookmarks