MarvinECL
(MarvinECL)
February 11, 2023, 11:29am
1
I have two uclasses and an compiler error here:
UCLASS(BlueprintType, Blueprintable)
class UCardCostFuncHolder : public UObject
{
GENERATED_BODY()
UCardCostFuncHolder() : CardCostDetails(FCardCost()){};
UCardCostFuncHolder(const FObjectInitializer& ObjectInitializer) : CardCostDetails(FCardCost()){};
UCardCostFuncHolder(const FCardCost& CardCost) : CardCostDetails(CardCost){};
public:
const FCardCost CardCostDetails;
};
UCLASS(BlueprintType)
class UTest_CardCost : public UCardCostFuncHolder
{
GENERATED_BODY()
};
And now visual studio give me an ERROR:
CardCostLibrary.h(11): error C2248: “UCardCostFuncHolder::UCardCostFuncHolder”: cannot access private member (declared in class “UCardCostFuncHolder”)
And when I check the code at that line, it’s just thie GENERATED_BODY() macro in class UTest_CardCost.
I think this error is related to unreal engine reflection system, and I want to know the solution about this error.
MarvinECL
(MarvinECL)
February 11, 2023, 11:48am
2
And it looks like the problem is caused by the inline expression on the constructor. Even if I remove the const keyword, this error still exists.
MarvinECL
(MarvinECL)
February 11, 2023, 12:06pm
3
I just tried to modify the constructor several times, and I think this problem is just I don’t know how to do constructor for uobject. Now I will learn about that.
Emaer
(Emaer)
February 11, 2023, 12:26pm
4
Base class constructor(s) should be public
(at least protected
) to be visible by child classes.
MarvinECL
(MarvinECL)
February 13, 2023, 6:03am
5
You are a lifesaver ! I’m so stupid ! I forget the scope specifer !
MarvinECL
(MarvinECL)
April 22, 2023, 7:56am
7
For dear friends visit this page, the Best Way to initialize an object in C++ in UE4 is:
Use Factory Function.
Forget about the raw C++ constructor. Use custom in class static factory function to initialize your object.