看到个例子:
在同一个头文件中定义结构类型相似的对象,根据宏定义不同获取不同的对象,主要用于增强代码的可读性:
例如:在头文件student.h中定义两个学生对象(小明和小红),两个对象互不干涉:
#ifdef MING
#define MING_AGE 20
#define MING_HEIGHT 175
#endif
#ifdef HONG
#define HONG_AGE 19
#define HONG_HEIGHT 165
#endif
/********头文件2:student.h********/
在源文件中使用这两个对象:
#include <stdio.h>
#define MING
#include "student.h"
#undef MING /*这样就只有在student.h中才能使用宏。*/
#define HONG
#include "student.h"
#undef HONG
int main()
{
printf("Xiao Ming's age is %d.\n", MING_AGE);
printf("Xiao Hong's age is %d.\n", HONG_AGE);
return 0
---------------------
作者:Hugoool
来源:优快云
原文:https://blog.youkuaiyun.com/u014170067/article/details/53561821
版权声明:本文为博主原创文章,转载请附上博文链接!