[gameprogrammer] problem with singleton

I tried to implement the cache class as a singleton. Here is the code:

class TVTextures {
 public:
 static TVTextures getCache() { return _instance;  };
 ~TVTextures();
 protected:
 TVTextures();
 static TVTextures _instance;
};

But whenever I try to use the class like this:
TVTextures::getCache().AddImage(STSTR,driver->getTexture("strength_i.jpg"));
i got an error a linking error: undefined reference to
`tower::TVTextures::_instance'
if I change _instance to be a pointer and the  getCache code to try make
sure the pointer is initialized to this:
 static TVTextures getCache() { 
if (_instance==0) _instance= new TVTextures();   <---
return _instance;  };

then I get the same error, but in the marked line. What Im doing wrong?


-- 
Roger D. Vargas
Linux User: 180787
ICQ: 117641572
jabber.ehtsc.co.cu: roger
"Object-oriented programming is an exceptionally bad idea which could
only have originated in California." 
- E.W. Dijkstra



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: