Last active
December 18, 2015 04:49
-
-
Save samrogerson/5728487 to your computer and use it in GitHub Desktop.
Nick wanted static options....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NicksClassOptions // singleton class | |
{ | |
private: | |
// make the default constructor and the copy constructor private | |
// to prevent extra versions of this floating around | |
NicksClassOptions() {}; | |
NicksClassOptions(const NicksClassOptions&); | |
// prevent people changing this | |
NicksClassOptions& operator=(const NicksClassOptions&); | |
public: | |
// example variable i like to have in a single class | |
int verbose; | |
// this is the only function we define on the class | |
static NicksClassOptions& O() | |
{ | |
// access the private constructor here; make it static so | |
// repeated calls get the same object | |
static NicksClassOptions singleton; | |
return singleton; | |
} | |
}; | |
//Access it like: | |
NicksClassOptions::O().verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment