Singleton is a pattern in Software Architecture. It is used to create a instance and there will be only one instance in system at any time. If you want to write this pattern in a file, it will be like that:
[codesyntax lang=”cpp” tab_width=”2”]
If you want write this pattern into different files, it will has Singleton.h Singleton.cpp and other files like that:
Singleton.h[codesyntax lang=”cpp” tab_width=”2”]
|
|
Singleton.cpp
[codesyntax lang=”cpp” tab_width=”2”]
main.cpp
[codesyntax lang=”cpp” tab_width=”2”]
But it dose not ensure this instance is only the same in the system. Because it will be destroyed and recreated.