- Unreal Engine 4 C uclass Analysis of error-prone constructors
- Generated_body
- Generated_uclass_body
You typically see two macros in any class of Unreal Engine 4:
- Generated_body ()
- Generated_uclass_body ()
This is sometimes said in a tutorial:
This statement is not rigorous and does not fully explain the difference between the Uclass_body () and the BODY ().
Specific analysis:
First of all, why there are two macro definitions, mainly considering that, after inheriting the parent class, it is necessary to change the contents of the parent class, the constructor initialization is also the case.
Here's how the next two approaches are different:
1.generated_body ()
If Generated_body () is defined, then it means that I do not need to use the parent class's constructor, that is, I cannot use the declaration of the parent class directly, but when I need to implement it, I have to declare it myself or I will get an error.
uclass () class Mycharacter_api Amycharacter: public acharacter {generated_body () Span style= "margin:0px; padding:0px; Color: #000088 ">public : Amycharacter (const fobjectinitializer& Objectinitializer); };
You can then implement this constructor of your own declaration in CPP and compile it.
AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { }
If you do not declare your own constructor, you will get an error:
MyCharacter.cpp (7): Error C2084: Function "Amycharacter::amycharacter (const Fobjectinitializer &)" already has a body
MyCharacter.h: note: See previous definition for ' {ctor} '
1.generated_uclass_body ()
If Generated_uclass_body () is defined, then it means that I use the constructor of the parent class, that is, I do not need to declare the constructor for myself, directly to implement the parent class declaration that constructor.
uclass () class Mycharacter_api Amycharacter: public acharacter {Generated_uclass_ BODY ()};
Then in the CPP file to implement, and do not need to declare in H, compiled through!
AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { }
If you also declare your own constructor, you will get an error:
uclass () class Mycharacter_api Amycharacter: public acharacter {Generated_uclass_ BODY () public : Amycharacter (const fobjectinitializer& Objectinitializer); };
This is the most common mistake.
Error C2535: "Amycharacter::amycharacter (const Fobjectinitializer &)": member function already defined or declared
Note: See the "amycharacter::amycharacter" statement
End.. Transfer from http://blog.csdn.net/qq_20309931/article/details/52964391
Unreal Engine 4 C + + Uclass constructors Error-prone analysis