http://www.csdn.net/expert/Topic/278/278912.shtm
解决方案 »
- 求助: error LNK1120: 1 unresolved externals
- VC6.0中DBGrid控件的Columns选项卡中的Column项中的下拉菜单中的内容有时候会没了,请问是怎么回事
- WinXP下,设定启动某个进程时,可以设定它的优先级吗?谢谢!
- VC连接mysql
- Dll问题
- 我的第一个dll的问题,麻烦各位了。。
- 关于EDIT控件改变字体颜色的问题
- 如何加密硬盘,有几种方法?
- 是大侠就出手相救
- 口令检测后再进入主程序,该怎么做,请帮我一下可以吗?
- 谁有Advanced c++ programming Style and Idioms (James Copliens)
- 谁知道YAMAHA 719E-S声卡的驱动程序在哪下?注意:是E-S呦!!!
//a.cpp:
//////////////
#include <windows.h>
...
int myGlobalVar;int SomeFunction()
{
myGlobalVar = 1;
}
////////////
//b.cpp:
///////////
extern int myGlobalVar;
int anyfunction()
{
myGlobalVar++;
}如果你定义的全局变量较多,
也可生成一个包含文件:
如
////////////
// myvar.h
/////////////
extern int myGlobalVar;////////////
//c.cpp:
///////////
#include "myvar.h"
int testfunction()
{
myGlobalVar--;
}
其它文件使用时,用extern;
CXxxApp theApp;
int iGlobals;
extern int iGlobals;
在某个.cpp中定义,如:int gvar; 如果在其他.cpp中要用,则:extern int gvar;定义CWinApp变量:
在CMyApp类中定义,如:int avar; 在其他.cpp中,AfxGetApp()->avar 来用它。
楼上说的都对,尽量少用全局变量。