Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM (Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: Allowing only one instantiation of a class Message-ID: <6590297@hplsla.HP.COM> Date: 12 Oct 89 17:48:48 GMT References: <672@suntops.Tops.Sun.COM> Organization: HP Lake Stevens, WA Lines: 32 //heres one approach: extern "C" { int printf(char* p, ...); void exit(int condition); }; class oneonly { const char* const nm; static int oneexists; public: oneonly(const char* const name):nm(name) { if (oneexists) {printf("Sorry: oneonly already exists\n"); exit(1);} else printf("this is the one and only oneonly: %s\n",nm); oneexists=1; } }; int oneonly::oneexists=0; // Lets see what happens when we try this: --------------------------------- oneonly theFirstOne("theFirstOne"); void main() { oneonly theSecondOne("theSecondOne"); oneonly* p = new oneonly("new_oneonly"); }