Download

Question about declaration of classes, structs, and enums in C++

I’ve been trying to follow the coding standards of Unreal, and I’m curious about a few things. I’ve been declaring structs and classes with a specified module API. What is the benefit of doing this? Is there any difference if I just leave it out?



USTRUCT(BlueprintType)
struct STEAMMATCHMAKING_API FSteamSessionSettings
{
GENERATED_BODY()

// ...
};


I wanted to follow the pattern above and declare an enum with module API, but the compile always fails. Is there a way (or a reason) to declare an enum with a module API? I know I can just remove the module API and it would work, but I’m curious why.



UENUM()
enum class STEAMMATCHMAKING_API ESteamReservationResponse : uint8
{
     // Getting compile error : Missing '{' in 'Enum'
};


Interestingly enough, Epic usually declares enums like this:



UENUM()
namespace EPartyReservationResult
{
     enum Type
     {
          // ...
     };
}


IIRC you don’t need to export enums.

The namespaced enums are a thing of the past really, and IMO should be avoided because then you are forced to use TEnumAsByte when using it with reflection, which can be pretty annoying.

If you have in C++ one Editor module using types from a Kismet module which uses types from a Runtime module… You must export dependency types using the module name macro, because each module code in that case is going to land in a different DLL.

If the only target of that type is to be exposed to Blueprints VM, export macro is not needed. Just UTHING() is already enough.