Is it possible to access to access and use static members within a class without first creating a instance of that class? Ie treat the the class as some sort of dumping ground for globals
James
On
Yes:
class mytoolbox
{
public:
static void fun1()
{
//
}
static void fun2()
{
//
}
static int number = 0;
};
...
int main()
{
mytoolbox::fun1();
mytoolbox::number = 3;
...
}
On
Yes, it's precisely what static means for class members:
struct Foo {
static int x;
};
int Foo::x;
int main() {
Foo::x = 123;
}
You can also call a static method through a null pointer. The code below will work but please don't use it:)