-3
我有一个简单的程序,如:如何在C函数中使用全局变量包含在其他文件
int velocity=0;
#include "extra.h"
int main()
{
extra();
return 0;
}
其中extra.h
是:
void extra(){
velocity += 1;
}
然而,当我编译此,我得到的错误:
extra.h:5:5: error: 'velocity' was not declared in this scope
很明显,我在extra.h
代码不能“看到”麦变量n.c,但为什么呢?我该如何解决?
尝试把速度变量.h文件来代替。 – uvr
@uvr这当然不是一个好的做法。 –
http://stackoverflow.com/questions/10422034/when-to-use-extern-in-c – willll