기본 콘텐츠로 건너뛰기

글

라벨이 singleton인 게시물 표시

C++ 에서 Singleton 형태

C++에서 Singleton 형태(Effective C++에서 참고) // 정의 class Singleton { private: // 외부 이용 제한 (생성과 복사, 삭제 제한이 목적)     Singleton() {}; // 생성자     Singleton(const Singleton& other);  // 복사 생성자     ~Singleton() {}; // 소멸자     //static Singleton* instance; // 내부에서 하나의 값으로 유지하기 위한 변수 public: // 외부 사용 허가     //static Singleton* GetInstance()     //{     //    if(instance == NULL)     //        instance = new Singleton();     //    return instance;     //}     static Singleton* GetInstance()     {         static Singleton ins;         return &ins;     } }; //Singleton* Singleton::instance = nullptr;  // static 정의 대한 클래스 외부 정의 // 사용시 Singleton::GetInstance() // 형태로 이용하거나 Singletone* instance = Singleton::GetInstance(); // 형태로 이용 이것말고도 Singleton 관련하여...