Error: Call to deleted constructor of 'juce::AudioParameterFloat'


#1

Hi, I am working with AudioParameterFloats for plugin automation, based off of the tutorial here: https://juce.com/doc/tutorial_audio_parameter

It seems strange to me that the tutorial recommends initializing AudioParameters via the new keyword, since in JUCE’s style guide it is clearly recommended to avoid using new except when absolutely necessary:

Do not use ‘new’ unless there’s no alternative. Whenever you type ‘new’, always treat it as a failure to find a better solution. If a local variable can be allocated on the stack rather than the heap, then always do so.

Therefore instead of:

addParameter (gain = new AudioParameterFloat (“gain”, // parameter ID
"Gain", // parameter name
0.0f, // mininum value
1.0f, // maximum value
0.5f)); // default value

I wanted to do:

private:
AudioParameterFloat time = AudioParameterFloat (“time”, “Time”, 0.1f, 1.0f, 1.0f);

and

addParameter(&time); //in constructor

But I get the error:

Call to deleted constructor of ‘juce::AudioParameterFloat’

What is causing this issue, and is there some reason that the new keyword should be used in this circumstance?


#2

Inheritance. In any case using “new” isn’t that harmful in this instance since the addParameter call will make the AudioProcessor take ownership of the pointer.


#3

Okay, what does calling the constructor using the new keyword do in terms of inheritance that calling the constructor regularly does not?


#4

The AudioParameter class as well as its Juce provided subclasses are marked non copyable, so you can’t do things like assign them around with operator =. You could change your parameter declaration to :

AudioParameterFloat time{ "time", "Time", 0.1f, 1.0f, 1.0f }; 

Which compiles but would then mess things up at run time since addParameter expects to be able to take ownership of the object. (Which it can not do if your parameter object is a value member of your AudioProcessor.)