Changes between Version 1 and Version 2 of code/Singleton
- Timestamp:
- Apr 12, 2017, 10:29:00 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/Singleton
v1 v2 3 3 == Description == 4 4 5 The [wiki: singleton] is an important design-pattern in advanced c++ coding. A singleton is a class, that allows only one existing instance at a time. This is achieved by overloading the constructor as a private function and the implementation of a static funciton that returns a pointer to the only existing instance (or creates the instance if it's not already existing). The pointer itself is stored in a static variable. This variable must be statically set to zero before you access the [wiki:singleton] the first time.5 The [wiki:Singleton] is an important design-pattern in advanced c++ coding. A singleton is a class, that allows only one existing instance at a time. This is achieved by overloading the constructor as a private function and the implementation of a static funciton that returns a pointer to the only existing instance (or creates the instance if it's not already existing). The pointer itself is stored in a static variable. This variable must be statically set to zero before you access the [wiki:Singleton] the first time. 6 6 7 This way you can retrieve a pointer to the [wiki: singleton] and access its member functions everywhere in the code without using ugly static objects or completely static classes.7 This way you can retrieve a pointer to the [wiki:Singleton] and access its member functions everywhere in the code without using ugly static objects or completely static classes. 8 8 9 9 == Example ==