I don't know what you think "purging" a variable is, but maybe this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
void f(bool reset = false)
{
staticint n = 0;
if (reset)
n = 0;
else
std::cout << n++ << '\n';
}
int main()
{
for (int i = 0; i < 5; ++i) f();
f(true);
for (int i = 0; i < 5; ++i) f();
}
#include <iostream>
class Func
{
int n = 0;
public:
void reset() { n = 0; }
voidoperator()()
{
std::cout << n++ << '\n';
}
};
int main()
{
Func f;
for (int i = 0; i < 5; ++i) f();
f.reset();
for (int i = 0; i < 5; ++i) f();
}