Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 0.94 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Check if instance exists and return reference in Singleton getInstance();
  2. class Song {
  3.  
  4. private:
  5.     Song song;
  6.     Song();
  7.     Song(Song const&); // don't implement
  8.     void operator = (Song const&); //don't implement
  9.  
  10. public:
  11.     static Song &getInstance();
  12. }
  13.        
  14. Song(Song const&); // don't implement
  15.     void operator = (Song const&); //don't implement
  16.        
  17. static S& getInstance()
  18. {
  19.     static S    instance; // Guaranteed to be destroyed.
  20.                           // Instantiated on first use.
  21.     return instance;
  22. }
  23.        
  24. Song(Song const&) = delete;
  25. void operator = (Song const&) = delete;
  26.        
  27. static S& getInstance()
  28. {
  29.     static S    instance; // Guaranteed to be destroyed.
  30.                           // Instantiated on first use.
  31.     return instance;
  32. }
  33.        
  34. Song(Song const&);
  35.        
  36. Song a;
  37. Song b = a; // calls copy constructor
  38.        
  39. void operator=(const Song&);
  40.        
  41. Song a;
  42. Song b;
  43. b = a; // calls assignment operator.
  44.        
  45. Song& operator=(const Song&);