我们在C语言中引用文件,有时候会出现重复引用的情况,为了避免发生此种情况,我们想到了一个解决方案。代码如下:
#include <stdio.h>
#include "one.h"
#include "two.h"
int main(){
printf("这是文件包含的解决方案!");
return 0;
}
上面引入了one.h的头文件,为了避免one.h与two.h的重复引用,我们可以多加三行代码。例如:在one.h中添加如下代码:
#ifndef _ONE_H_
#define _ONE_H_
void one();
#endif
在two.h的头文件中也添加,如下代码:
#ifndef _TWO_H_
#define _TWO_H_
#include "one.h"
void two();
#endif
好了,今天就学习到这里。慢慢再理解消化一下吧。