Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

singleton c++

// NOTE in c++ a singleton is equivalent to just a namespace

class Singleton
{
public:
    // Prevents any type of copy or new instance
	Singleton(const Singleton&) = delete;
    void operator=(const Singleton&) = delete;
  
    static Singleton& Get()
    {
    	static Singleton instance;
    	return instance;
    }
  
    static int GetData() { return Get().someData}
private:
    Singleton() {}
	int someData = 1;
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #singleton
ADD COMMENT
Topic
Name
2+9 =