Possible Duplicate:
What is the purpose of forward declaration?
Forward Declaration vs Include
i am a bit confused with the #include *.h file inclusion in both the header and cpp files. I see that some .h files are included in the header file and some in the corresponding cpp file. I would guess that all needed .h files would need to be included in the header file and thus do not see a reason why they have been included in the cpp file. Is there any specific reason for this?
Also, I see that some needed classes have been included in the header file using Class ClassName;. How is this different from just including the ClassName.h in the header file?
In your first paragraph you seem to say that the same .h file is included in the class’ header file and the class’ .cpp file? That’s just an oversight since including a file that includes other files, by definition, also includes those other files. You can remove the duplicate include in the .cpp file.
In your second paragraph, what you are seeing is a forward declaration of a class. If you don’t need a class’ definition in the header than sometimes it’s good practice to just forward declare it. This way, files that include the header aren’t dependent on the class’s definition. This cuts down on dependencies between files. An example of only needing a forward declaration is if a class contains a member variable that’s a pointer to a class as opposed to the class itself.