Q:

How can I do some code work just like a singleton?

Possible Duplicate:
C++ Singleton design pattern. 

How can I create only one instance of a class and share that instance with all my header and source files without using a singleton? Can you provide a simple example?

A:

You can do this:
class Sample
{
   /*** your code **/
   public:
    Sample();
    void DoWork();
    int  GetValue();
  /*** other functions ***/
};

Sample & OneInstance()
{
    static Sample instance;
    return instance;
}

//Use OneInstance everywhere like this
OneInstance().DoWork();

Note Sample is not a Singleton, but you can use OneInstance() function as if it's one and the same instance of Sample, which you use everywhere!
You can use it to initialize some global variables also like this:
int g_SomeValue= OneInstance().GetValue();

which cannot be done with global static instance of Sample. That is because of this: 
static initialization order fiasco

