How does Epic avoid undeclared identifiers?

How does Epic avoid undeclared identifiers when using classes in other classes without including the header files?

For instance, TcpMessageTransport.h does not include TcpMessageTransportConnection.h or any other header file and yet can still use FTcpMessageTransportConnection without throwing undeclared identifier errors. I’m assuming this is accomplished in the Build.cs file somehow but I can’t find any resources regarding this and nothing I have tried has worked.

Hi,

as you can see in line 14 in TcpMessageTransport.h, the type class FTcpMessageTransportConnection is forward declared as class type. As long as there are only pointers or references to this type (e.g. function parameters, member pointers) the compiler does not need to know the the actual class design/implementation7contents. It only needs to know that it exists and that it is a class type. That is what the forward declaration tells him.

In the cpp file, where it is actually used (i.e. member access, function calls) the header file needs to be included.

Se also here on wikipedia: link

This is a pure C++ feature, and has nothing to do with Epic’s build system or code generation.

Well, that would make sense. I must have accidentally deleted them from my file. I went and looked at the github source and sure enough, they are there. Well shoot. time to verify my data. yay!

Ok, after verifying the install was complete, the includes and forward declarations were still missing. I am currently in 4.14 and the github repo for 4.14 reflects my findings. There are no includes or forward declarations at all in that file. They are however there for 4.15. Interesting.

You are right, in 4.14 the forward declarations are missing. The explaination, why this does not lead to an error is, that because in the file TcpMessagingPrivatePCH.h the two headers TcpMessageTransportConnection.h and TcpMessageTransport.h are included in exacly this order coincidentally. This is a bit dirty and Epic fixed this in version 4.15. I remember that I read something about “every file includes/declares what it needs” ind the 4.15 release notes.

Just out of curiosity, how is the PCH included?