I am reading some of the Epic Games UnrealEngine4 source code and see couple of practices which make me wonder if I miss some of essential C++ magic.
static inline member methods in class declaration.Here @dividebyzero user actually sheds very important info regarding the effect of using static inline,at least with GCC compiler - inline placement similar to how MACRO functions behave.
Another interesting practice I can see is how UE4 creates interfaces for inheritance.Here is example based on how OpenGL backend module in UE4 looks like:
class FOpenGLBase { public: static FORCEINLINE void UnmapBufferRange(GLenum Type, uint32 InOffset, uint32 InSize) UGL_REQUIRED_VOID };
Where UGL_REQURED_VOID
is replaced with default function body,which reports "unimplemented" method error if called on this base class.
Next come inheritance of the above class:
struct FOpenGL3 : public FOpenGLBase
{
static FORCEINLINE void UnmapBuffer(GLenum Type)
{
glUnmapBuffer(Type);
}
static FORCEINLINE void UnmapBufferRange(GLenum Type, uint32 InOffset, uint32 InSize)
{
UnmapBuffer(Type);
}
};
I even didn't know it was possible for a struct to inherit from class and vice -versa.
I understand that static + inline makes it possible to generate unique function body per function call,which makes it possible to put different body but with same signature in subclass's declaration. But then I also wonder why one needs virtual inheritance for small methods if it is possible to override static inline methods in subclass just like this? Why such an approach is not common? (at least from my experience I find it uncommon)
PS: I wasn't sure if this question format is ok for SO or should be rather put in CodeReview site.