Send to a Friend

t3h_87der's avatar

How can I reset the clock in this (C++) timer function?

Asked by t3h_87der (6points) August 22nd, 2010

Here’s the code:

——————————————————————
#ifndef TIMER
#define TIMER

#include <ctime>

bool reset = false;

class Timer {
clock_t counter;
public:
Timer(): counter(0) {};

bool elapsed(clock_t ms)
{
clock_t tick = std::clock();
if(tick – counter >= ms)
{
counter = tick;
return true;
}

return false;
}
};

#endif
————————————-

My question is how can I reset the time held in this function back to 0? This is a piece of code that my friend sent me to use for a program im working on, and it works great but i cant reset it. All answers are appreciated.

Using Fluther

or

Using Email

Separate multiple emails with commas.
We’ll only use these emails for this message.