我组织了我的程序,将每个实体拆分到自己的文件中。这是这样的。
main.c
#include "student.h"
#include "subject.h"
#include "classroom.h"
#define PI 3.14
int sum(int a, int b);
学生.h
typedef struct st student;
学生.c
#include "student.h"
主题.h
typedef struct sb subject;
主题.c
#include "subject.h"
教室.h
typedef struct cr classroom;
教室.c
#include "classroom.h"
我的问题是,在教室里我需要学生和学科。我应该如何包括这个?我应该将它包含在教室.h或教室.c中吗?
#include "student.h"
#include "subject.h"
其次,我在main.c上有一些东西被所有人使用,比如sum()和PI
在头文件中包含实现或在实现文件中包含头文件的正确方法是什么?我应该包含头文件还是实现文件?
如果我将所有内容都放在一个文件上,它编译得很好,但我做的不对,它不会编译。