Tutorial by Examples

This example has been lifted from the Q & A section here:http://stackoverflow.com/a/1008289/3807729 See this article for a simple design for a lazy evaluated with guaranteed destruction singleton: Can any one provide me a sample of Singleton in c++? The classic lazy evaluated and correctly de...
class API { public: static API& instance(); virtual ~API() {} virtual const char* func1() = 0; virtual void func2() = 0; protected: API() {} API(const API&) = delete; API& operator=(const API&) = delete; }; class WindowsAPI ...
C++11 The C++11 standards guarantees that the initialization of function scope objects are initialized in a synchronized manner. This can be used to implement a thread-safe singleton with lazy initialization. class Foo { public: static Foo& instance() { static Foo inst; ...
There are times with multiple static objects where you need to be able to guarantee that the singleton will not be destroyed until all the static objects that use the singleton no longer need it. In this case std::shared_ptr can be used to keep the singleton alive for all users even when the static...

Page 1 of 1