How to define global variable MFC 中全局变量的定义
来源:互联网 发布:免费点歌软件 编辑:程序博客网 时间:2024/05/22 06:33
1.We could define a global variable in Stafx.h.
2.But for the sake of readability,Open two files in Notepad,save as .cpp(source file) and .h(header file) files,in the .cpp file we define the global variable ,in .h declare as external variable,and include the .h header file in the required class .
eg:
In Globalsv.cpp // this is the .cpp file
#include "Globalsv.h" //include the header file
int gv; //define the global variable here
In Globalsv.h declare the external variable
extern int gv; //this is the .h file and we declare the external variable here
and then,and don't forger to add Globalsv.h and Globalsv.cpp to the project.
At last you can use the global variable gv in any class you want to by including the header file Globalsv.h in your class.
chinese:
1可以在stdafx.h中定义
2但为了可读性,可以打开两个记事本,分别保存为.cpp和.h文件,在.cpp中定义,在.h中声明为外部变量,在所需要的类中包含.h头文件
eg:
在Globalsv.cpp中
#include "Globalsv.h"
int gv;
在Globalsv.h中声明为外部变量
extern int gv;
然后,将Globalsv.cpp和Globalsv.h添加到工程,
然后就可以在任意你想用变量gv的类的前面包含Globalsv.h
- How to define global variable MFC 中全局变量的定义
- how to force global variable which define in a static library to initialize?
- MFC中全局变量的定义
- 055.Global Variable 全局变量
- 055.Global Variable 全局变量
- MFC中定义全局变量
- MFC中定义全局变量的方法
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- MFC中全局变量的定义及使用
- 全局变量的global的定义和使用
- Log4J 详细注释版
- 技术员创业失败指南(上):合作创业的陷阱
- COM原理及应用----ActiveX控件
- COM原理及应用----COM发展——COM+
- 【Delphi-语法函数库】Delphi分割字符串
- How to define global variable MFC 中全局变量的定义
- VS2008中文版安装ASP.NET MVC Beta
- asp.net上传多个附件
- 在JSF DataTable 中实现多选
- Struts+Spring+Hibernate练习
- Schema语法之简单类型
- 【Delphi-ADO】Delphi数据网格自动适应宽度
- COM原理及应用----基于COM的程序设计
- hibernate查询语句--HQL