Hi I have an snippet of code that is a singleton class ( I believe) that uses 'new' and some other scope and static qualifiers in a way I have not seen before. Because I do not know what it is called I cannot find any information on what it does or its purpose. Code below:
In the myClass.h file I have
class myClass
{
private:
static myClass sm_myClass;
myClass();
public:
static void Create(void);
};
and in the myClass.cpp I have
#include "myClass.h"
#include <new>
myClass* p_myClass = NULL;
myClass myClass::sm_myClass;
myClass::myClass()
{
}
void myClass::Create(void)
{
p_myClass = &sm_myClass;
new (p_myClass) myClass();
}
My questions are:
1 - What is happening at line 6 ( myClass myClass::sm_myClass; ) of the .cpp file
2 - What is happening at line 16 ( new (p_myClass) myClass(); ) of the .cpp file
3 - What is the overall purpose of using a class in this way?
I really hope that this question is not a repeat. I searched for an answer for a while but didn't know what terms to even search. Thanks for any help.