I'm new to c++ so i don't know much about it yet
so basically i have this code
static Application& getInstance()
static Application* mInstance;
mInstance = this;
The constructor of a class belongs to an object, i.e. if it is called explicitly by the code somewhere it creates an object in the memory (on the stack or on the heap). So if you do not call the constructor somewhere it is never executed.
I see only the point why this can run is that you did not specify the initial value of the
mInstance pointer. This means that its value is undefined and accidentally can have some valid address. If the
run() method does not touch the
mInstance object itself your code can run sometimes but sometimes not. This is the problem of uninitialized variables in C++.
But I suggest to follow the right singleton pattern:
mInstance as a
getInstance() function should call the constructor if
(Just a general hint: Avoid passing
this in constructor to somewhere else because at that point the object is not fully constructed and in case of multi-thread application it can cause issues.)