# C++ call parent-constructor manually?

**URL:** <https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629>\
**Category:** C++\
**Tags:** constructors, unreal-engine, CPP, question\
**Created:** [May 26, 2016, 10:46am UTC](https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629 "2016-05-26T10:46:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [May 26, 2016, 10:46am UTC](https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629/1 "2016-05-26T10:46:15Z")

</div>

I would like to have full control over when the parent-constructor is called (it seems that UE4 calls it automatically and before the child-constructor). I have a piece of code in BaseEnemy (that inherits from BaseCharacter) that must be performed in the constructor, but before the BaseCharacter-constructor runs.

```
ABaseEnemy::ABaseEnemy()
{
  // <My code that must be performed before the base-constructor here>

  // Call super constructor <<<<<<<<< this is not possible?

  // The rest of my awesome code.
}
```

---

<div class="post-metadata">

**Author:** ![Steve\_Robb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steve\_Robb](https://forums.unrealengine.com/u/Steve_Robb)\
**Post date:** [May 26, 2016, 11:01am UTC](https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629/2 "2016-05-26T11:01:00Z")

</div>

Hi,

It is impossible to do what you are trying to do. The only way to do it is with multiple bases, but UE4 requires that the UObject base is listed first:

```
// illegal - UnrealHeaderTool will reject this
UCLASS()
class ABaseEnemy
    : public ClassWhoseConstructorMustExecuteBeforeAActorsConstructor
    , public AActor
{
};

```

Steve

---

<div class="post-metadata">

**Author:** ![zimzimdz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zimzimdz](https://forums.unrealengine.com/u/zimzimdz)\
**Post date:** [May 26, 2016, 1:20pm UTC](https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629/3 "2016-05-26T13:20:29Z")

</div>

More than that this is a general and 101 C++ spec !!  
[http://www.learncpp.com/cpp-tutorial/113-order-of-construction-of-derived-classes/](http://www.learncpp.com/cpp-tutorial/113-order-of-construction-of-derived-classes/)

---

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [May 26, 2016, 1:33pm UTC](https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629/4 "2016-05-26T13:33:33Z")

</div>

Oh I see. I’m still too used to using C#.

---

<div class="post-metadata">

**Author:** ![Steve\_Robb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steve\_Robb](https://forums.unrealengine.com/u/Steve_Robb)\
**Post date:** [May 26, 2016, 1:45pm UTC](https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629/5 "2016-05-26T13:45:53Z")

</div>

You can’t do that in C# either.

---

<div class="post-metadata">

**Author:** ![Napoleonite](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Napoleonite](https://forums.unrealengine.com/u/Napoleonite)\
**Post date:** [May 26, 2016, 2:53pm UTC](https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629/6 "2016-05-26T14:53:21Z")

</div>

Then it must have been Javascript or Ruby because I’m sure I used it before in another language not long ago. But indeed both C++ and C# won’t allow it.

---

<div class="post-metadata">

**Author:** ![ReflectorRick](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ReflectorRick](https://forums.unrealengine.com/u/ReflectorRick)\
**Post date:** [November 23, 2021, 4:02pm UTC](https://forums.unrealengine.com/t/c-call-parent-constructor-manually/358629/7 "2021-11-23T16:02:58Z")

</div>

C++ allows multiple inheritance, it’s just Unreal that doesn’t. As soon as you put UCLASS() at the top of a class, you’ve got to follow Unreal’s rules.
