小编Mei*_*eio的帖子

为什么必须要有静电力?

谁能为我澄清这段代码?我已经做了一些研究,以了解引用和静态信息,但在此示例中,我仍然不了解静态信息的作用。以及为什么它必须首先存在(如果缺少static,编译器会发出警告,程序可能会崩溃,为什么?)。

int & foo(int b)
{
    static int a = 7;


    a += b;
    return a;
}

int main() {

    int & x = foo(0);
    int & y = foo(1);
    cout << (x + y);

}
Run Code Online (Sandbox Code Playgroud)

c++ static

0
推荐指数
1
解决办法
93
查看次数

标签 统计

c++ ×1

static ×1