Main Content

Fix Polyspace Compilation Errors About In-Class Initialization (C++)

When a data member of a class is declared static in the class definition, it is a static member of the class. You must initialize static data members outside the class because they exist even when no instance of the class has been created.

class Test
{
public:

	static int m_number = 0;
};

Error message:

Error: a member with an in-class initializer must be const

Corrected code:

in file Test.hin file Test.cpp
class Test
{
public:
static int m_number;
};
int Test::m_number = 0;