Skip to content

Instantly share code, notes, and snippets.

@mhseiden
Last active December 11, 2015 17:58
Show Gist options
  • Save mhseiden/4638443 to your computer and use it in GitHub Desktop.
Save mhseiden/4638443 to your computer and use it in GitHub Desktop.
/**
* NOTE - I haven't compiled this, so there may be small errors.
* However, the concepts shown are correct.
*/
// In the *.h file
class MyClass;
class MyClass {
public:
/** Static Singleton accessor. Use a ref for easy access and use **/
static MyClass& get();
/** Instance Methods **/
// ...
private:
MyClass(); // Constructor
~MyClass(); // Destructor
// Could hide equals operator and copy constructor...
/** Other private data **/
// ...
};
// In the *.c file
static MyClass& MyClass::get() {
static MyClass singleton;
return singleton;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment