# Must explicitly initialize the member which does not have a default constructor

**URL:** <https://forum.juce.com/t/must-explicitly-initialize-the-member-which-does-not-have-a-default-constructor/31822>\
**Category:** The Projucer\
**Created:** [February 18, 2019, 3:37am UTC](https://forum.juce.com/t/must-explicitly-initialize-the-member-which-does-not-have-a-default-constructor/31822 "2019-02-18T03:37:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SharodMarce](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@SharodMarce](https://forum.juce.com/u/SharodMarce)\
**Post date:** [February 18, 2019, 3:37am UTC](https://forum.juce.com/t/must-explicitly-initialize-the-member-which-does-not-have-a-default-constructor/31822/1 "2019-02-18T03:37:35Z")

</div>

Hello I am new to using the forums of Juce. It is a great software so far, but while I was working on making a synthesizer I ran into an error that I do not know how to fix. I am in the process of adding external midi input.

“Constructor for ‘SharodVstAudioProcessor’ must explicitly initialize the member ‘keyboardComponent’ which does not have a default constructor”

Code:  
Header & CPP file

 ![imgonline-com-ua-twotoone-InoeWqZuwXn](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/6/675def3a25b293deb1b5e73c74e5a5d717f63327.jpeg)

I believe my way of initializing the midiKeyboardState object in the constructor of the cpp is at fault, but I am not entirely sure how to add it into my constructor with the audio processor object.

P.S. if someone could also point me in the direction of the forum topic of how to post code I would be very grateful.

---

<div class="post-metadata">

**Author:** ![theaudioprogrammer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/theaudioprogrammer/32/18383_2.png) [@theaudioprogrammer](https://forum.juce.com/u/theaudioprogrammer)\
**Post date:** [February 18, 2019, 5:57am UTC](https://forum.juce.com/t/must-explicitly-initialize-the-member-which-does-not-have-a-default-constructor/31822/2 "2019-02-18T05:57:08Z")

</div>

Hi, it’s difficult for me to really understand what you’re doing here. Follow this tutorial step-by-step and let me know how it goes 🙂

---

<div class="post-metadata">

**Author:** ![mcmartin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mcmartin/32/7432_2.png) [@mcmartin](https://forum.juce.com/u/mcmartin)\
**Post date:** [February 18, 2019, 8:10am UTC](https://forum.juce.com/t/must-explicitly-initialize-the-member-which-does-not-have-a-default-constructor/31822/3 "2019-02-18T08:10:25Z")

</div>

> [@SharodMarce](#):
>
> P.S. if someone could also point me in the direction of the forum topic of how to post code I would be very grateful.

Use three back-ticks characters on their own line to start a code block and three back-ticks on their own line to end a code block:

````
```
int foo () 
{
    return 42;
}
```

````

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [February 18, 2019, 10:20am UTC](https://forum.juce.com/t/must-explicitly-initialize-the-member-which-does-not-have-a-default-constructor/31822/4 "2019-02-18T10:20:24Z")

</div>

> [@SharodMarce](#):
>
> “Constructor for ‘SharodVstAudioProcessor’ must explicitly initialize the member ‘keyboardComponent’ which does not have a default constructor”

Classes like `MidiKeyboardComponent` only have 1 constructor, and that constructor takes arguments. In this case, it requires a MidiKeyboardState and an orientation.

the MidiKeyboardState must be passed as a reference, which means it must already exist before it gets passed to the MidiKeyboardComponent.

You can initialize it like this:

```auto
struct MyClass
{
    MidiKeyboardState state;
    MidiKeyboardComponent keyboardComponent{state, MidiKeyboardComponent::Orientation::Horizontal};
};

```

This is legal code because it takes advantage of the Class Member Initialization Order rules. Member variables are initialized from top to bottom, so the `MidiKeyboardState` is fully initialized before the MidiKeyboardComponent is.

---

<div class="post-metadata">

**Author:** ![SharodMarce](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@SharodMarce](https://forum.juce.com/u/SharodMarce)\
**Post date:** [February 24, 2019, 5:47am UTC](https://forum.juce.com/t/must-explicitly-initialize-the-member-which-does-not-have-a-default-constructor/31822/5 "2019-02-24T05:47:36Z")

</div>

Thanks a bunch I decided to make a new content component class instead, thanks a bunch!
