C++: Problem in finding code execution time
<p>To find the execution time of my code as given below, I have written a <code>Timer</code> class.</p>

<pre><code>Timer::StartTimer();
DoOperation();
cout&lt;&lt;"Time elapsed: "&lt;&lt;Timer::GetTime();
</code></pre>

<p>I get error that startTime and endTime are undefined. I couldn't quite get the problem. Can you please help.</p>

<p>File:Timer.h</p>

<pre><code>#include &lt;sys/time.h&gt;

class Timer
{
    static timeval startTime, endTime;

public:
     static void StartTimer();
     static long int GetTime();
};
</code></pre>

<p>File: Timer.cc</p>

<pre><code>#include "Timer.h"

void Timer::StartTimer()
{
    gettimeofday(&amp;startTime, NULL);
}

long int Timer::GetTime()
{
    long int seconds, useconds, mtime;
    gettimeofday(&amp;endTime, NULL);
    seconds  = endTime.tv_sec  - startTime.tv_sec;
    useconds = endTime.tv_usec - startTime.tv_usec;
    mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
    return(mtime);
}
</code></pre>
