Is there any issue with using forward declaration in header files instead of includes when it's possible?
It will compile faster, however i am not entirely sure if it's a good idea.
Thank you for answers!
Jump to content
Posted 06 January 2014 - 11:09 AM
Yes, it is almost always a good idea to forward declare wherever possible. Remember that header files and source files are, respectively, the interface and the implementation. Any file that includes header file will also include its includes. If you have an header that includes a rather expensive file, then those that also include that header will also take longer to compile. If you move the expensive include to the implementation, and forward declare in the header, then only the source file will take longer to complile. Additionally, you also prevent circular inclusions. See problem #2 in Organizing Code Files in C and C++.
Posted 06 January 2014 - 11:42 AM
Depends what you're wanting to forward declare I guess.
There's a time and a place for both (includes and forward declarations). Use forward decls where possible, but don't be afraid to use includes if you need to.
Studying BSc Computer Games Programming @ De Montfort University, Leicester.
On a year long placement as a Junior Programmer at Exient Ltd, Oxford (worked on the recently released Angry Birds Go!)