我的github

会发现它是一个宏定义

// Include a redundant semicolon at the end of the generated code block, so that intellisense parsers can start parsing
// a new declaration if the line number/generated code is out of date.
#define GENERATED_BODY_LEGACY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_,__LINE__,_GENERATED_BODY_LEGACY);
#define GENERATED_BODY(...) BODY_MACRO_COMBINE(CURRENT_FILE_ID,_,__LINE__,_GENERATED_BODY);

那么问题来了,BODY_MACRO_COMBINE又在哪里呢?像是在套娃似的。。

它的目的是为了给当前的类生成一些东西。。

参考1:https://zhuanlan.zhihu.com/p/483857843

参考2:https://www.freesion.com/article/5001284410/

 CURRENT_FILE_ID的定义在generated.h中找到。

__LINE__为generated_body()函数所在的行数。

把两者拼接在一起得到一个新的宏定义:mygame1_Source_mygame1_mygame1GameModeBase_h_15_GENERATED_BODY

该宏定义里面又包含了四个宏定义的函数。同样是在generated.h里可以找到。

参考:https://zhuanlan.zhihu.com/p/626783433

>>宏 GENERATED_UCLASS_BODY() 与 GENERATED_BODY() 简析:

https://www.cnblogs.com/tomato-haha/p/17434952.html

跟以往不同,当你创建一个新的UE4类时,您将注意到的第一件事是.cpp文件中缺少任何构造函数。此外,那些目光敏锐的人会发现.h文件中的宏也有所不同。GENERATED_BODY()宏允许在不定义构造函数的情况下构建类。如果需要构造函数,可以将该宏更改为更熟悉的GENERATED_UCLASS_BODY()。如果这样做,则必须为类提供构造函数,否则将无法在Visual Studio中生成项目。因此,您的代码将如下所示:

// MyActor.h
UCLASS()
class TESTCONSTRUCTOR_API AMyActor : public AActor
{
    GENERATED_UCLASS_BODY()   
};

/*********************************/

// MyActor.cpp

#include "MyActor.h"

AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
{
    // Class constructor/initialization code
}

 

posted on 2023-09-25 23:46  XiaoNiuFeiTian  阅读(69)  评论(0编辑  收藏  举报