- Gof/Singleton . . . . 7 matches
어디에서 Singleton class들이 그들을 등록하는가? 한가지 가능성은 그들의 생성자에서다. 예를들어 singleton의 subclass인 MySingleton 은 다음과 같이 구현할 수 있다.
MySingleton::MySingleton () {
Singleton::Register ("MySingleton", this);
물론, 코드 어디에선가 클래스를 인스턴스화하지 않으면 생성자는 호출되지 않을 것이다. C++에서는 MySingleton의 static instance를 정의함으로서 이 문제를 잘 해결할 수 있다. 예를 들어, MySingleton 클래스의 구현부를 포함하는 화일에 다음과 같이 정의하면 된다.
static MySingleton theSingleton;
Found 1 matching page out of 7555 total pages (5000 pages are searched)
You can also click here to search title.