我明白什麼是標題守衛,但我從來沒有看到它是如何用於更大的項目。我目前正在編寫一個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?
謝謝我會看看這篇論文。我還用一個例子更新了我的第一篇文章。 –