No. С видом ваших ошибок компилятора, ваш класс не будет работать.
@Galik has provided invaluable sources как вы на самом деле хотите построить синглтон. Но давайте посмотрим на ваши.
class A {
static A *instance = NULL; // NULL isn't even a thing, but assuming you mean nullptr you can't assign a static like this
public:
A() {
if (instance) {
this = instance; // this can't be assigned
} else {
instance = this; // this is correct
}
}
};
который даст вам следующее:
class A {
static A *instance;
public:
A() {
// if there's no instance, this is the one we'll use
if (!instance) {
instance = this;
}
}
};
A* A::instance = nullptr;
Что не мешает вам строить более чем один в любом случае.
Я рекомендую вам изучить этот ответ, который описывает, как сделать синглтон: http://stackoverflow.com/a/1008289/3807729 – Galik