back
1 comments
Could you comment on why there are lots of (non-templated) function definitions in the headers? Looking at it, it doesn't actually look like there is that much, from the two random files I opened. In the first random file I opened[0] I didn't really understand why some of the functions (see link) were defined in the header.

In another file[1] it seemed to make more sense (getters and setters, along with a smallish class where I guess you didn't want to bother making a new file).

[EDIT] Could I also ask why you have defined some very large classes entirely in the cpp files[2]

Also, thanks for this, very interesting to read the source for other large projects.

[0] https://github.com/CRYTEK-CRYENGINE/CRYENGINE/blob/63418e7c9...

[1] https://github.com/CRYTEK-CRYENGINE/CRYENGINE/blob/63418e7c9...

[2] https://github.com/CRYTEK-CRYENGINE/CRYENGINE/blob/63418e7c9...

There are a few reasons you would do this in CPP, though I'm not sure whether they apply to this case.

You might put function definitions in headers to (1) avoid linking a library (2) explicitly declare a function as inline, maybe (3) it's simple enough that you don't lose readability by inlining it.

The one about putting large classes entirely in CPP files: I wouldn't do it this way for readability reasons, but putting it in the CPP file directly does restrict anybody else from using what is supposed to be a one-off helper class. I think that's the intent here.

The only reason I have seen it done (and done it myself) is to avoid having to link to a library, so you put the implementation in the header of that library. No idea if that's the case here though.
Most logical reason: in past they shipped binary engine SDK with headers only and probably even sell licenses without full source code. This is reason quite few things defined in headers so it's easier to understand how code works without access to full source.