Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 1 and Version 2 of code/Singleton


Ignore:
Timestamp:
Apr 12, 2017, 10:29:00 PM (3 years ago)
Author:
landauf
Comment:

fixed links

Legend:

Unmodified
Added
Removed
Modified
  • code/Singleton

    v1 v2  
    33== Description ==
    44
    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.
     5The [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.
    66
    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.
     7This 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.
    88
    99== Example ==