Why do some folks continue to add subsequent duplicate #include
some duplicate header files in their projects?
Bat.h
#include <SFML/Graphics.hpp>
Pong.cpp
#include "Bat.h"
#include <SFML/Graphics.hpp>
Wasn't they paying attention?
CodePudding user response:
The idea is to include the headers that the current file depends on. E.g. in Pong.cpp, you're not obliged to know whether Bat.h (which you supposedly also included) depends on <SFML/Graphics.hpp>
or on another graphics library or no graphics library at all. Since double include is something we can prevent (using include guards, #pragma once
), it's not a problem to list every dependency, but it's an issue to miss one.