I am using QNX momemtics IDE 5.0.1 with a virtual machine VmPlayer to run QNX Client. I am using singleton pattern for a class. When calling the instance of the class I am getting the error "Undefined reference to "error: 'constexpr' needed for in-class initialization of static data member 'DemoClass* DemoClass::s_instance' of non-integral type [-fpermissive]". The code snippet is as below:
class DemoClass
{
static DemoClass*s_instance = nullptr;
public :
DemoClass();
virtual ~DemoClass();
//singleton
static DemoClass* GetInstance()
{
if (!s_instance)
s_instance = new DemoClass;
return s_instance;
}
}
I am calling the getter function in another class as below:
class AppMgr
{
DemoClass* m_demo;
public:
AppMgr();
virtual ~AppMgr();
void Load();
);
void AppMgr::Load()
{
m_demo = = DemoClass::GetInstance();
}
I added the definition of the static member still facing the error. Please suggest.