How to define global variable MFC 中全局变量的定义
2008-11-18 17:45
363 查看
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
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 force global variable which define in a static library to initialize?
- CodeIgniter 定义“全局变量-global variable”,可以在所有controller,model和view中使用
- MFC中定义全局变量和全局函数的方法
- 在VC++MFC下如何定义全局变量和全局函数
- 在MFC下如何定义全局变量和全局函数(转)
- MFC全局变量的定义与使用(类对象)
- MFC定义全局变量
- 在MFC下如何定义全局变量和全局函数
- MFC定义的宏、全局函数及全局变量
- mfc 定义全局变量
- PHP Global定义全局变量使用说明
- MFC定义全局变量
- MFC中全局变量的定义及使用
- 在MFC下如何定义全局变量和全局函数
- MFC全局变量的定义和使用
- 在MFC下如何定义全局变量
- MFC中全局变量的定义及使用
- PHP Global变量定义当前页面的全局变量
- 在MFC下如何定义全局变量和全局函数
- 【C++】【MFC】定义全局变量的方法