三个文件pc_main.h,modpc_com.h,modpc_com.cpp
modpc_com.h中的内容
extern char com_file_name[30];//for comminication
extern int g_mqid;//it is the message queue id
modpc_com.cpp中的内容
#include "modpc_com.h"
int g_mqid=5;
char com_file_name[30]="shared_file";
pc_main.cpp中的内容
#include "modpc_com.h"
int main()
{
cout<
}
modpc_com.h中的内容
extern char com_file_name[30];//for comminication
extern int g_mqid;//it is the message queue id
modpc_com.cpp中的内容
#include "modpc_com.h"
int g_mqid=5;
char com_file_name[30]="shared_file";
pc_main.cpp中的内容
#include "modpc_com.h"
int main()
{
cout<
}
三个文件pc_main.h,modpc_com.h,modpc_com.cpp
modpc_com.h中的内容
extern char com_file_name[30];//for comminication
extern int g_mqid;//it is the message queue id
modpc_com.cpp中的内容
#include "modpc_com.h"
int g_mqid=5;
char com_file_name[30]="shared_file";
pc_main.cpp中的内容
#include "modpc_com.h"
int main()
{
cout<
}
modpc_com.h中的内容
extern char com_file_name[30];//for comminication
extern int g_mqid;//it is the message queue id
modpc_com.cpp中的内容
#include "modpc_com.h"
int g_mqid=5;
char com_file_name[30]="shared_file";
pc_main.cpp中的内容
#include "modpc_com.h"
int main()
{
cout<
}
本文介绍了一个C++程序中全局变量的声明与定义方式,包括如何在头文件中声明并在源文件中定义全局变量。通过示例展示了extern关键字的使用以及变量的实际赋值方法。
206





