Singleton (1) 썸네일형 리스트형 싱글톤 패턴 C++로 구현하기(Singleton pattern) 싱글톤 패턴이란? 싱글톤 패턴은 아무리 많은 객체를 생성해도, 단 하나의 인스턴스만을 생성한 것과 같은 디자인 패턴이다. 원래 같으면 여러 개의 객체를 생성하면 각각의 객체가 가진 변수는 값을 공유하지 않는다. #include class Math{ public: int score = 0; void setscore(int a){ score = a; }; int getscore(){ return score; }; }; using namespace std; int main(){ Math *math1 = new Math(); //math1이라는 객체 생성 Math *math2 = new Math(); //math2이라는 객체 생성 cout getscore() 이전 1 다음