我正在清理正在处理的C ++项目中的包含,并且我一直在想是否应该将直接使用的所有标头明确包含在特定文件中,还是应该仅包含最低要求。
这是一个例子Entity.hpp:
#include "RenderObject.hpp"
#include "Texture.hpp"
struct Entity {
Texture texture;
RenderObject render();
}
(让我们假设对它的前向声明RenderObject不是一种选择。)
现在,我知道其中RenderObject.hpp包括Texture.hpp-我知道,因为每个人RenderObject都有一个Texture成员。不过,我还是明确地将Texture.hppin 包含在内Entity.hpp,因为我不确定依赖于in是一个好主意RenderObject.hpp。
因此:这是一种好的做法吗?
#ifndef _RENDER_H #define _RENDER_H ... #endif。
#pragma once解决它,不是吗?