static variable c++

      No Comments on static variable c++

All static member is shared by all objects. All static data is initialized to zero, if no other initialization present . You must definition out side class to use static variable

class Helloworld {
static int x;
void foo();

int Helloworld::x;

void Helloworld::foo() {
Helloworld::x = 10;

If you want to initialize static member inside class definition you have to use keyword: “constexpr”

Leave a Reply

Your email address will not be published. Required fields are marked *