   static variables in singleton class?
  i am trying to write a singleton texture manager for my engine right now. the only problem is that im trying to define static attributes in this class. i am getting these linking errors (LNK2001):TextureMgr.obj : error LNK2001: unresolved external symbol "private: static unsigned int * TextureMgr::m_ids" (?m_ids@TextureMgr@@0PAIA)TextureMgr.obj : error LNK2001: unresolved external symbol "private: static char * * TextureMgr::m_names" (?m_names@TextureMgr@@0PAPADA)TextureMgr.obj : error LNK2001: unresolved external symbol "private: static int TextureMgr::m_current" (?m_current@TextureMgr@@0HA)=============================CODE================================#ifndef _TEXTUREMGR_#define _TEXTUREMGR_#include "Textures.h"#define MAX_TEXTURES 20class TextureMgr{static TextureMgr* s_pTextureMgr;static intm_current;static GLuintm_ids[MAX_TEXTURES];static LPSTRm_names[MAX_TEXTURES];public:TextureMgr(){ s_pTextureMgr = this;/* m_current = 0;*/ }~TextureMgr(){ delete s_pTextureMgr; }// TEMPstatic void Enable(){ glEnable(GL_TEXTURE_2D); }static void Disable(){ glDisable(GL_TEXTURE_2D); }// END OF TEMPstatic texture*CreateTexture(LPSTR filename);static voidBind(LPSTR filename);};#endif _TEXTUREMGR_if you could please tell me what im doing wrong that would help me out alot!   
  The link errors are caused by your not defining the static members.  All static members must be defined somewhere, usually in the class''s corresponding .cpp file.For instance, in TextureMgr.cpp you''d  have the following line at file scope:TextureMgr* TextureMgr::s_pTextureMgr;..and something like that for each static class member.However, this is somewhat beside the point since this is the wrong way to make a singleton.  Your ctor will stomp over all prior instances, and the dtor will work the first time but probably crash every time after that.A singleton should have no static members except for the instance.  That instance should be returned from a "GetInstance" member function, and I prefer to have the instance be a function-local static object within that function.  The ctor should be private, so only the singleton can create itself.  The dtor should be private as well, but some compilers (MSVC 6.0) need it to be public.BTW, there was a very compelling discussion recently on singleton design, basically saying that you should only use singleton templates, and not build it into the class.  Anybody have that bookmarked?HTTP 500 strike #1...and the site is reaaaallly slow tonight.  ;  What''s the point of having static variables in a singleton?  I mean, if you enforce one instance then all variables are *essentially* static.  ;  Just did a quick search:Is this what you meant?;  Thanks for the search, TH, but that''s half the post I was looking for (apparently I''d melded two in my head).  The other one was a pretty long discussion (I think about 3 pages) about singleton being over- and inappropriately-used.  It stuck in my head because I disagreed with the post at first, but the author eventually brought me over to his side.    Think Liberally.