Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to create a single global object

Status
Not open for further replies.

EngineersForge

Technical User
Aug 26, 2003
15
CA
Hello,

How does one create a single global object that cannot be minipulated in any way? It has to be created immidiatly when the main process starts and must not be used to create more of the same type (refering to class types)?

I was thinking there is a way through the defualt constructor being put under the pravate interface some how, and the class type declaired as const? Does that work in any way???

thanx a bunch,

MK
 
class xx
{
private:
xx(){}
static xx* obj;
public:
static xx* create_xx()
{
if(!obj)obj = new xx();
return obj;
}
};
xx* xx::eek:bj = NULL;
......
int main()
{
xx* yourSingleTon = xx::create_xx();.....

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top