QT C++中声明和引用外部结构体变量-OK

QT C++中声明和引用外部结构体变量-OK
参考链接:https://blog.csdn.net/SSXY002/article/details/121900506
谢疏影 于 2021-12-13 10:58:32 发布

1、在头文件list_function.h中声明结构体,并用extern声明外部变量
// 声明结构体变量
typedef struct{
char number[30]; //学号
char name[30]; //姓名
char sex[30]; //性别
char tel[30]; //电话
char loc[30]; //地址
}Student;

typedef struct{
Student* elem[N]; //储存空间的基地
int length; //数据结构的长度
}SqList;

// 在头文件中用extern声明外部变量
extern SqList *L;

2、在list_function.cpp文件中进行实例化
SqList *L;

3、然后在其他.cpp文件中使用 #include list_function.h 头文件就可以调用这个结构体变量了。
4、在QT 5.15.2中测试通过

posted on 2023-01-03 16:18  patton88  阅读(1188)  评论(0编辑  收藏  举报

导航