Last active
December 11, 2015 17:58
-
-
Save mhseiden/4638443 to your computer and use it in GitHub Desktop.
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
/** | |
* 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