3 ms·
That sounds like hard mode, the easy solution is to just initialize them the first time they are used. GetInstance(){ if (!instance)instance = new Foo; return i
by josefx 3y ago
That sounds like hard mode, the easy solution is to just initialize them the first time they are used. GetInstance(){ if (!instance)instance = new Foo; return instance;}, add a lock if you need thread safety and done.
- MichaelMoser123 3y agoYes, you fix the problem by calling the initialization stuff from a single point.
- rcxdude 3y agoor just: Foo &getInstance() { static Foo instance; return instance; } Guaranteed to be threadsafe by the standard, even.