Quote:
Originally Posted by jayaraj_ev View Post
And can you tell me where and how you can design a singleton class without using dynamic allcation.
Code:
class csection{
private:CRITICAL_SECTION sect;
public: csection() { ::InitializeCriticalSection(&sect);} 
~csection() { ::DeleteCriticalSection(&sect); } 
void lock(){::EnterCriticalSection(&sect);}
void unlock(){::LeaveCriticalSection(&sect);}
};

csection g_singleton_cs;

class singleton
{private:
//[...]
singleton & get_instance()
{
    g_singleton_cs.lock();
       static singleton instance;
    g_singleton_cs.unlock();
     return instance;
}
};