I want to overload a function that has arguments of:
void TimedPrint(std::string name, TYPE x, sf::Time printSpeed)
so I can use other data types like vectors. But to do this I need each function call to have its own sf::Clock (basically an object that counts and returns a sf::Time).
Example:
1 2 3 4 5 6 7 8 9 10
void TimedPrint(std::string name, float x, sf::Time printTime)
{
static sf::Clock clock;
if (clock.getElapsedTime() > printTime)
{
std::cout << name << ": " << x << std::endl;
clock.restart();
}
}
But this doesn't work when I try to call the same function twice seeing the static is only made once. Will I have to make a vector of objects that do what I want to do, or is there any way I can use only functions?
> I need each function call to have its own sf::Clock
You can achieve this by creating a class with private: sf::Clock and member function void TimePrint(...)
Then, you can be sure that each object has its own clock
I left the arguments as you had them, however, I would seriously consider passing name and time values in Foo's constructor and changing TimedPrint to accept just the single typed argument.