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

#1

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

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.

0 Likes

#2

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 :slightly_smiling_face:

0 Likes

#3

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;
}
```
0 Likes

#4

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:

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.

0 Likes

#5

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

0 Likes