如果你稍微了解一点编译的知识你就会知道怎么用了。 如果你有一个全局变量 int iGlobe;你可以在某一个.c文件中定义它(比如在temp1.c中)。而你的程序使用了多个.c文件(比如temp2.c temp3.c temp4.c)。 在这些.c文件中你都需要使用这个变量iGlobe,于是你可以在temp2.c中写到 int i = iGlobe; 但是你编译temp2.c时,编译器不会知道iGlobe是个什么东西,它也就无法为这个变量预留一个位置(因为它不知道iGlobe到底有多大)。 所以你需要在temp2.c 的头部写上 extern int iGlobe;这时编译器就会知道iGlobe是个什么东西了。如果你觉得我的答案对你有用,请你帮我顶一下 http://expert.csdn.net/Expert/topic/2148/2148457.xml?temp=.9692194 谢谢。
{
i++; //i未定义,但已用extern声明,在下面再定义i
}int i=5;void CGgDlg::OnOK()
{ add(); CString str;
str.Format("%d",i);
AfxMessageBox(str); //结果为6
}
如果你有一个全局变量 int iGlobe;你可以在某一个.c文件中定义它(比如在temp1.c中)。而你的程序使用了多个.c文件(比如temp2.c temp3.c temp4.c)。
在这些.c文件中你都需要使用这个变量iGlobe,于是你可以在temp2.c中写到
int i = iGlobe;
但是你编译temp2.c时,编译器不会知道iGlobe是个什么东西,它也就无法为这个变量预留一个位置(因为它不知道iGlobe到底有多大)。
所以你需要在temp2.c 的头部写上 extern int iGlobe;这时编译器就会知道iGlobe是个什么东西了。如果你觉得我的答案对你有用,请你帮我顶一下
http://expert.csdn.net/Expert/topic/2148/2148457.xml?temp=.9692194
谢谢。