2 // This tests two things:
3 // 1. there is an annoying warning.
4 // singleton.C:26: warning: `class singleton' only defines private constructors and has no friends
5 // egcs fails to see that there is a public static accessor function.
6 // 2. the program crashes, because apparently the static variable s in
7 // singleton::instance() is considered constructed although the ctor
8 // exited via an exception. (crash changed to nonzero return here)
12 static singleton& instance() {
16 int check() {return initialized;}
19 singleton() : initialized(1) {
20 if ( counter++ == 0 ) throw "just for the heck of it";
23 singleton( const singleton& rhs );
24 void operator=( const singleton& rhs );
29 int singleton::counter;
35 return singleton::instance().check()-2;