本文介绍了函数中的静态变量不适用于C而是C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的......这个问题让我发疯了......

但代码很简单,我确实已经谷歌了。



代码:



Okay...This problem is driving me crazy...
but the code is pretty easy, and I did already google it.

Code :

void f(int c) {
	static int foo = c;
}





这是我用Google搜索的ed



[]



它表示C中的静态与'C ++'相当。

但我的编译器只是继续说





Here is what I googled"ed"

Difference between static in C and static in C++?? - Stack Overflow[^]

It says static in C is 'equalvalent to' C++.
but my compiler just keep saying

"Initializer element is not constant"



和我也谷歌它,它只是一直在说常量问题....

但是'const'不是我想要的,我只需要保留变量'foo'!



我尝试过:



Google


and also I did google it, it just keeps saying the 'constant' problem....
but 'const' is not what I want, I just need to reserve the variable 'foo' !

What I have tried:

Google

推荐答案



void f(int c) {
    static int foo = 0;
    foo = c;
}


这篇关于函数中的静态变量不适用于C而是C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 19:33