http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

TheGrumpyProgrammer



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gameprogrammer] Re: problem with singleton



Have you instanciate the member _instance like this:

TVTextures TVTextures::_instance;

anywhere in your code?

----- Message d'origine -----
De : "Roger D. Vargas" <roger@ehtsc.co.cu>
À : "Game programmer list" <gameprogrammer@freelists.org>
Envoyé : lundi 14 juin 2004 17:05
Objet : [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
>
>
>



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