c++ Problem with timer counter being shared between multiple instances of a class
<p>I have a simple timer class in a game, intended to allow me to make an entity do something every so many seconds. It has two functions:</p>

<pre><code>void Timer::GameTimer() // Gets time between frames
{
    ::ElapsedTime = Clock.GetElapsedTime();
    Clock.Reset();
}
</code></pre>

<p>This just updates the ElapsedTime Global so that it can be grabbed by anything that needs it. It's placed inside the gameloop.</p>

<p>Then the important one:</p>

<pre><code>bool Timer::tCounter(int total) // Returns true every 'total' seconds
{
    static float ftime; // Variable to hold the mounting elapsed time
    static int n; // Counter variable for true trigger

    ftime += ElapsedTime;

    int itime = (int)ftime; //Truncate

    if(!(itime%total) &amp;&amp; itime != 0)
    {
        n++;
    }
    else
    {
        n = 0;
    }

    if (n == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}
</code></pre>

<p>Timer is instantiated inside the Entity class as Timer::Timer timer</p>

<p>The function is then called inside Entity::Update once per loop for every instance of the entity class in the game:</p>

<pre><code>if (timer.tCounter(2))
    {
        Do stuff
    }
</code></pre>

<p>The problem is it doesn't seem to count uniquely for each instance of Entity, resulting in only one doing stuff at a time and other weird stuff occasionally happening. The problem seems to be the static variables being shared. How do I ensure that this tCounter function holds unique variables for each instance that calls it?</p>
