# 【UE4 Reflection】Why const member in parent UClass would be private for child UClass ?

**URL:** <https://forums.unrealengine.com/t/ue4-reflection-why-const-member-in-parent-uclass-would-be-private-for-child-uclass/768562>\
**Category:** C++\
**Tags:** Reflections, UClass, unreal-engine, question\
**Created:** [February 11, 2023, 11:29am UTC](https://forums.unrealengine.com/t/ue4-reflection-why-const-member-in-parent-uclass-would-be-private-for-child-uclass/768562 "2023-02-11T11:29:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarvinECL](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marvinecl/32/680524_2.png) [@MarvinECL](https://forums.unrealengine.com/u/MarvinECL)\
**Post date:** [February 11, 2023, 11:29am UTC](https://forums.unrealengine.com/t/ue4-reflection-why-const-member-in-parent-uclass-would-be-private-for-child-uclass/768562/1 "2023-02-11T11:29:32Z")

</div>

I have two uclasses and an compiler error here:

```auto
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;
};

```

```auto
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.

---

<div class="post-metadata">

**Author:** ![MarvinECL](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marvinecl/32/680524_2.png) [@MarvinECL](https://forums.unrealengine.com/u/MarvinECL)\
**Post date:** [February 11, 2023, 11:48am UTC](https://forums.unrealengine.com/t/ue4-reflection-why-const-member-in-parent-uclass-would-be-private-for-child-uclass/768562/2 "2023-02-11T11:48:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MarvinECL](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marvinecl/32/680524_2.png) [@MarvinECL](https://forums.unrealengine.com/u/MarvinECL)\
**Post date:** [February 11, 2023, 12:06pm UTC](https://forums.unrealengine.com/t/ue4-reflection-why-const-member-in-parent-uclass-would-be-private-for-child-uclass/768562/3 "2023-02-11T12:06:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Emaer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/emaer/32/570877_2.png) [@Emaer](https://forums.unrealengine.com/u/Emaer)\
**Post date:** [February 11, 2023, 12:26pm UTC](https://forums.unrealengine.com/t/ue4-reflection-why-const-member-in-parent-uclass-would-be-private-for-child-uclass/768562/4 "2023-02-11T12:26:35Z")

</div>

Base class constructor(s) should be `public`(at least `protected`) to be visible by child classes.

---

<div class="post-metadata">

**Author:** ![MarvinECL](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marvinecl/32/680524_2.png) [@MarvinECL](https://forums.unrealengine.com/u/MarvinECL)\
**Post date:** [February 13, 2023, 6:03am UTC](https://forums.unrealengine.com/t/ue4-reflection-why-const-member-in-parent-uclass-would-be-private-for-child-uclass/768562/5 "2023-02-13T06:03:52Z")

</div>

You are a lifesaver ! I’m so stupid ! I forget the scope specifer !

---

<div class="post-metadata">

**Author:** ![MarvinECL](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marvinecl/32/680524_2.png) [@MarvinECL](https://forums.unrealengine.com/u/MarvinECL)\
**Post date:** [April 22, 2023, 7:56am UTC](https://forums.unrealengine.com/t/ue4-reflection-why-const-member-in-parent-uclass-would-be-private-for-child-uclass/768562/7 "2023-04-22T07:56:09Z")

</div>

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.
