singleton pattern with global variable
<p>Hey
Consider the following code parts:</p>

<p>this is Timing.h:</p>

<pre><code>class Timing {

public:
    //creates a single instance of timing. A sinlgeton design pattern
    Timing *CreateInstance();
private:
    /** private constructor and a static instance of Timing for a singleton pattern. */
    Timing();
    static Timing *_singleInstance;
};

extern Timing timing;
</code></pre>

<p>and this is Timing.cpp:</p>

<pre><code>Timing timing;  //a global variable of Timing

Timing *Timing::CreateInstance() {
    if (!_singleInstance) {
        _singleInstance = new Timing();
    }
    return _singleInstance;
}
</code></pre>

<p>Now, since I want to hold one object of Timing i made as a singleton pattern (only one timing can be created). In my exercise requirements, they say I can choose between 2 option:<br>
create one instance of timing in the main() which is in another file and each time pass a reference of this instance to the rest of the methods in the program, or I can create a global Timing timing and state in .h file extern Timing timing. I chose the second option. However, i have some difficulties to connect between the global variable and my singleton pattern.
how to i create the instance of timing in the Timing.cpp file?<br>
i tried Timing timing = CreateInstance(), however this doesn't work..<br>
i can't create the instance in the main() because then i will be implementing the first option..<br>
do i need to write in main timing.CreateInstance() ?<br>
i hope i explained my self clearly.
thanks for your help</p>
