能在所有类中访问的全局变量
解决方案 »
- MySQL+ADO两个线程同时读取数据库出现问题,求解
- 关于获取角色名的疑问?
- 如何编程获取windows任务栏上所有窗口的名字?
- 【求助】请教关于 fopen的问题,和 CException的问题,多谢
- WIN2000Server上安装不了DXSDK9.0吗?
- 现在用ado在数据库里查询的时候界面总是死掉一样,
- 有没有API,可以将显示切换到当前桌面?
- 初学者提问!1、在MFC ActiveX中如何&在哪里 添加方法?2、如何创建一静态窗体!
- 用 vc 做数据库报表。请问有什么好的方法?
- 关于视图的问题
- *** 基础太差, 将DLL中创建的窗口句柄 传递到主程序中? 不能用return***
- 字符问题请教
如://in ex1.cpp
int a; //全局变量定义然后在其它的需要这个变量的Cpp文件中写
//in ex2.cpp
extern int a; //外部变量声明就可以了。
使用时
void CDlgDlg::OnButton2()
{
((CDlgApp*)AfxGetApp())->str = "test";
}
不要忘记了包含头文件
extern int m;
在 A.cpp 中,
int m;然后要用 m 时
#include "A.h"
在 A.h 中
extern int m;
在 A.cpp 中,
int m;然后要用 m 时
#include "A.h"
在 A.h 中
int m;
在 A.cpp 中,
extern int m;
还有Static和extern能不能同时存在?
然后我在对话框中用a,在dlg.app中包含了w2view.h 运行却出现以下错误,不知道什么原因,请高手指教?
d:\日历1\w2view.h(21) : error C2143: syntax error : missing ';' before '*'
d:\日历1\w2view.h(21) : error C2501: 'CW2Doc' : missing storage-class or type specifiers
d:\日历1\w2view.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers
Error executing cl.exe.
Creating browse info file...
如://in ex1.cpp
int a; //全局变量定义然后在其它的需要这个变量的Cpp文件中写
//in ex2.cpp
extern int a; //外部变量声明就可以了。
extern "变量"
如下:
//*.cpp
int a;int *()//函数实现
{
}
如果要在其它文件中使用
使用extern再声明一个就可以了
如下:
extern int a;