How to fix: Audio Processor &p provides no initializer for:

I asked this question in audio plugins but I haven’t received any responses so I am posting it here.
Hi I am a beginner to JUCE and C++ in general and I am following the Audio Programmers Guide for making a sampler, and I am getting one final error that I can not figure out. It says: Audio Processor &p provides no initializer for:
Any help would be appreciated!
Here is the code I have:

InstrumentLibraryOneAudioProcessorEditor::InstrumentLibraryOneAudioProcessorEditor (InstrumentLibraryOneAudioProcessor& p)
    : AudioProcessorEditor (&p), audioProcessor (p)
    // Make sure that before the constructor has finished, you've set the
    // editor's size to whatever you need it to be.
    samplerButton.onClick = [&]() {processor.loadFile(); };
    setSize(800, 500);


    InstrumentLibraryOneAudioProcessor& audioProcessor;
    juce::TextButton samplerButton{ "Sampler" };

    InstrumentLibraryOneAudioProcessor& processor;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InstrumentLibraryOneAudioProcessorEditor)


#ifndef JucePlugin_PreferredChannelConfigurations
     : AudioProcessor (BusesProperties()
                     #if ! JucePlugin_IsMidiEffect
                      #if ! JucePlugin_IsSynth
                       .withInput  ("Input",  juce::AudioChannelSet::stereo(), true)
                       .withOutput ("Output", juce::AudioChannelSet::stereo(), true)
    for (int i = 0; i < numVoices; i++)

        mSampler.addVoice(new SamplerVoice());

    formatReader = nullptr;

void InstrumentLibraryOneAudioProcessor::loadFile()
    FileChooser chooser{ "Select Audio File" };

    if (chooser.browseForFileToOpen())
        auto file = chooser.getResult();
        formatReader = formatManager.createReaderFor(file);
    BigInteger range;
    range.setRange(0, 128, true);

    mSampler.addSound(new SamplerSound("Sample", *formatReader, range, 60, 0.1, 0.1, 10));


    Synthesiser mSampler;
    const int numVoices{ 6 };
    AudioFormatManager formatManager;
    AudioFormatReader* formatReader{ nullptr };

I did not include the whole code, only the sections I changed.

Why the two InstrumentLibraryOneAudioProcessor references?

    InstrumentLibraryOneAudioProcessor& audioProcessor;
    InstrumentLibraryOneAudioProcessor& processor;

This surely can’t be what you intend?

The second one is not initialized in the initializer list of the constructor, that’s the compiler’s complaint. References must always be initialized.

Where and what would I add to in order to initialize the second one? I have never heard of what an initializer list is or how to add to one.

Well, you can better drop the second one, “processor” - I bet you are not using it in the rest of your code. If your are, replace it with audioProcessor.

An initializer list is a recommended way to initialize variables / objects that you have declared in your class (in the header file). Simple variables do not need to be initialized there, but at least references must be assigned there; I prefer to initialize objects there as well.

Look at the first line in your code:

    : AudioProcessorEditor (&p), audioProcessor (p)

what follows after the colon “:” is an initializer list.

Anything you haven’t heard of before, be it about C++, JUCE, DSP, Google it! Or ask here :wink:
C++ is a pretty difficult language, you need to have regular doses of new lessons, otherwise you will never improve your skills.



Thank you it is working now!