Defining static members in C++

You will have to initialize the static variable in a .cpp file and not in the class declaration.

When you declare a static variable in the class, it can used without instantiating a class.

//Header file
class Test
{
  public:
    static int j;
};

//In cpp file

//Initialize static variables here.
int Test::j = 0;

//Constructor
Test::Test(void)
{
   //Class initialize code
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)