我明白什么是标题守卫,但我从来没有看到它是如何用于更大的项目。我目前正在编写一个OpenGL抽象层,我大多需要包含相同的文件。更大的项目的标题守卫
所以我的第一个幼稚的做法是做这样的事情:
#ifndef GUARD_H
#define GUARD_H
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <GL/glfw3.h>
#include <glload/gl_core.h>
#include <glload/gll.h>
#endif // GUARD_H
这样我就可以做#include "guard.h"
。但是我意识到这不是一个很好的解决方案,因为如果我想添加一个简单的包含函数呢?
是的我可能可以将我的所有包括在这个文件中,但我也不确定这是否是一个好主意。
你怎么会推荐我来构造我的头警卫?你能推荐我任何资源吗?
更新1:小例子
test.h
#ifndef TEST_H
#define TEST_H
#include <glm/glm.hpp>
class test{
};
#endif
test1.h
#ifndef TEST1_H
#define TEST1_H
#include <glm/glm.hpp>
class test1{
};
#endif
现在我包括在我的测试类GLM。但是如果我想要做这样的事情怎么办?
#include "test.h"
#include "test1.h"
int main(){
//...
}
不要包括#include <glm/glm.hpp>
2次在main?
谢谢我会看看这篇论文。我还用一个例子更新了我的第一篇文章。 –