The answer depends on what's in the code in each of the files. I think the best way to illustrate the point is with an example:
Say I have been tasked to create a computer model of a solar system. Say I have created a class called Matter, which describes properties of matter in it's various states. I then create another class called World. A world contains Matter, so I embed it in the definition of World and include it at the top. I then proceed to create a class called Moon. A moon also contains Matter, so once again I embed the class Matter into the definition of Moon, and include it at the top. Now I want to create a solar system using my newly designed objects, so I create a new file called Solarsystem, which contains my main() function to start the program. Obviously, in order to use both my World and my Moon in the Solarsystem, they will both have to be included into the Solarsystem file. When I do that, the compiler will complain that I've defined the Matter class twice. How to fix it? Well there are two solutions:
1) Solution 1 is what you proposed doing above: I could delete the #include "Matter.h" statements from both World and Moon, and then put #include Matter.h" at the top of my Solarsystem file. This will work, but it poses a potentially annoying problem. In order for this to work you have to keep all your file dependencies in order. Since Matter is embedded into World and Moon, they depend on Matter to function properly. The compiler reads things straight through from top to bottom, so in order to avoid generating an error it will have to encounter the definition of Matter before World or Moon. That means that I'll have to remember to put the #include "Matter.h" statement before the #include "World.h" and #include "Moon.h". This may not seem like such a big deal in a small program, but you can see where this would become a massive headache in a larger program that included many other files, all with there own file dependencies. It also makes your code more difficult for others to use, because they have to know all these file dependencies so they can include things in the proper order.
2) Solution 2 is what I have described above. With this method, the compiler is automatically checking to see if another file has already been included. (Or more accurately for the method above, defined.) In this case, for my Solarsystem function to use World and Moon, all I have to do is include them both, and the compiler will take care of making sure that Matter isn't defined twice. To do this the inclusion statements for the example I've illustrated would look something like this:
1 2 3 4 5
|
//World.h file
#ifndef Matter_h //Remember, this is an arbitrarily chosen name
#define Matter_h
#include "Matter.h"
#endif
|
1 2 3 4 5
|
//Moon.h file
#ifndef Matter_h
#define Matter_h
#include "Matter.h"
#endif
|
1 2 3 4 5
|
//Solarsystem.cpp file
#include <iostream>
using namespace std;
#include "Moon.h"
#include "World.h"
|
Note that the inclusions can be done normally in the Solarsystem file, because all the other files already have the inclusion check included. Hence if I wanted to write yet another class, Orbit, that has both World and Moon embedded into it, I would be able to just add
#include "Orbit.h"
to the Solarsystem.cpp file. (Provided the World and Moon were included into Orbit as I outlined above.)
I hope this helps.