I've been programming with Unreal Engine for a while but I want my code to be a bit more consistent, and one thing that I'm not sure how to handle consistently are dependencies. I've seen some people only including files in their .cpp file, and then using forward declarations in their header, I've seen some people just including files in both .h and .cpp files whenever they need to use a class, and I've seen people mixing both. I was looking at some sample projects made by Unreal and they're really inconsistent. What's considered "good practice" when it comes to dependencies?
Asked
Active
Viewed 108 times
0
-
1It depends. There are advantages and disadvantages to all approaches. Hiding includes in cpp files takes more work but generally results in faster compilation and helps isolate different pieces of code – Alan Birtles May 23 '22 at 06:31
-
1Forward declare in .h (if possible), include in .cpp. – Osyotr May 23 '22 at 07:56
-
1The engine itself is pretty consistent - only include in the .cpp unless the header needs a full definition. This is not necessarily the right approach in every C++ project but it almost certainly is for unreal game code. – George May 24 '22 at 06:14