In your code block above, you put that Rectangle attempts to compile before Point. |
When compilation starts, each cpp file is taken in turn. The pre-processor scans through it, and everywhere it finds a
#include<someFile>
it finds
someFile
and copies it completely, into the cpp file, at that line. Your cpp file included Rectangle.h and then Point.h, so when those files are copied into the cpp file, Rectangle.h is copied first, and thus is before Point.h
Did you remember to use guards?
http://en.wikipedia.org/wiki/Include_guard
They will stop you repeating header files through the code. If Rectangle.h includes Point.h (which, as I explained above, basically means a complete copy of Point.h exists at the start of Rectangle.h), and then Rectangle.cpp also includes Point.h, you end up with Point.h copied out twice, which means your definition of Point.h exists twice - hence the
redefinition
error. The guards can stop this happening.
http://en.wikipedia.org/wiki/Include_guard
Once you understand that #include<someFile> creates an exact, complete copy of <someFile> at that point, it all becomes much clearer.