View Single Post
Go4Expert Member
5Feb2009,19:30  
jayaraj_ev's Avatar
Quote:
Originally Posted by zamjad View Post
Without going into advantages and disadvantages here is the simplest implementation of Singleton without using Heap

Code:
  Singleton* Singleton::CreateObject() 
  {
    static Singleton obj;
    return &obj;
  }
This will be useful in single threaded application.
Hi,
Good that u tried to do one without dynamic allocation. But one thing we should be carefull about is Static objects get created at start of program, so the objects gets created before main() which calls its constructor before. How we implement inside constructor also matters.