Hello!
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!
Melkon
Hello!
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!
Melkon
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++.
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.
BSc Computer Games Programming (De Montfort University) Graduate
Worked on Angry Birds Go! at Exient Ltd
Co-founder of Stormburst Studios