#include <iostream>
using namespace std;
void foo()
{
static int count = 0;
if(count<5)
{
count++;
cout<<count<<endl;
foo();
}
else
{
cout<<"count > 5"<<endl;
}
}
int main()
{
foo(); //increment count from 0 to 5
foo(); //count is already at 5
return 0;
}
这是一个例子