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


Hi, I am working with AudioParameterFloats for plugin automation, based off of the tutorial here:

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:

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


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?


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.


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


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.)