Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ static members in class

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

like image 447
Dark Templer Avatar asked Nov 21 '25 02:11

Dark Templer


1 Answers

Yes, it's precisely what static means for class members:

struct Foo {
    static int x;
};

int Foo::x;

int main() {
    Foo::x = 123;
}
like image 111
Pavel Minaev Avatar answered Nov 22 '25 15:11

Pavel Minaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!