Skip to content

Instantly share code, notes, and snippets.

@samrogerson
Last active December 18, 2015 04:49
Show Gist options
  • Save samrogerson/5728487 to your computer and use it in GitHub Desktop.
Save samrogerson/5728487 to your computer and use it in GitHub Desktop.
Nick wanted static options....
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