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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

instance of class

Status
Not open for further replies.

revit

Programmer
Oct 27, 2001
36
IL
i want to creat a static instance of class- meaning an object that can be shared by all the other classes, i made
a new field in my class t:
static t* MyInstance;

and a function:
static t* instance()
{
if(MyInstance==NULL)
{
MyInstance=new t();
}
return MyInstance;
}


from the cpp file i created a new instance of the class t:
t::MyInstance=NULL;

but something is wrong because i recieved this error: nresolved external symbol "public: st....

please help!
 
Sounds like you would benefit from the "Singlton" design pattern.

For that... the constructor is protected or private. I also think that MyInstance should be declared in the cpp as

t* t::MyInstance = NULL;

and instance should look like

t* t::instance()
for the function declaration unless that is from the header file and you inlined the function. In the cpp you do not need to declare them as static functions

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top