阅读背景:

[C++]局部静态变量在递归中只被初始化一次

来源:互联网 
#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;
}#include <iostream>

using namespace std;

void



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: