Where is the declaration of owner?

Hey guys! Today I have a question related to C++.
In all my plug-ins I pass a reference to the AudioProcessor to the constructor of the AudioProcessorEditor instance. To be honest I just adapted it from the tutorials I have watched and read. Documenting my code for my thesis I stumbled upon something I really don’t understand.

I do it as such:
ExampleAudioProcessorEditor ( ExampleAudioProcessor (& owner ) ) ;

Now I could not find where owner has been declared. Can somebody maybe explain this? Is this maybe a C++ convention that I don’t know?
Cheers, Luke

Hey Luke,

This looks a bit strange. This is code inside of the constructor of your editor?

Could you please post a bit more of your class. It’s normal to see a lot of references to your processor as it’s calling base class constructors.

If you look in your processor you can see where your editor is created:

AudioProcessorEditor* AudioProcessor::createEditor()
    return new AudioProcessorEditor (*this);

the this pointer would be my guess to where that owner has come from, but im a bit curious as to how you’ve deviated from the generated plugin projects created by the projucer.

A normal editor constructor may look something like this:

AudioProcessorEditor::AudioProcessorEditor (AudioProcessor& p)
    : AudioProcessorEditor (&p), processor (p)
    // Make sure that before the constructor has finished, you've set the
    // editor's size to whatever you need it to be.
    setSize (UI_WIDTH, UI_HEIGHT);

so the p is the this* from the function in the processor. then p is passed to the base class constructor for the AudioProcessorEditor, and a copy of it is stored as processor.

Hey Jake!

Thanks for your answer. This is in my Editor.cpp file:
DelayEditor::DelayEditor (DelayAudioProcessor(& owner))
: AudioProcessorEditor(owner)


This is in my Editor.h:
class DelayEditor : public AudioProcessorEditor,
public SliderListener,
public Timer

DelayEditor (DelayAudioProcessor(& owner));


And this is in my Processor.cpp file:
AudioProcessorEditor* DelayAudioProcessor::createEditor()
return new DelayEditor (*this);

Okay. Now even more question arise. Why is a “this” (the AudioProcessor) dereferenced? Does this maybe mean that when running the plugin a pointer to DelayAudioProcessor is created?
Now what I just don’t understand is, that we are passing the content to what “this” points to (indicated by the asterisk) to an instance of the DelayEditor class, which expects an an address:
DelayEditor (DelayAudioProcessor(& owner));

Or am I wrong?

The editor constructor takes a reference to the AudioProcessor, so when the editor is created *this is used to pass the current AudioProcessor object as a reference. (I suppose a reference is used instead of a pointer because it wouldn’t make sense for the GUI editor to exist without the AudioProcessor being a valid object too.)

Ah yes, I think I get that, but, with the asterisk i dereference the object, don’t I? So if you’d ask me I would pass a reference like so:

new DelayEditor (this);

Without the asterisk.

What harm do you think dereferencing the object does since the constructor call expects a reference anyway? ( * ) If the editor constructor wanted a pointer, then you could just pass “this” instead of “*this”. Either way it works pretty much the same, the Juce code just has been designed to work with a reference to the AudioProcessor instead of a pointer. (Which makes sense to avoid giving the impression the passed in AudioProcessor could be a null pointer.)

Note that “this” is a pointer, not a reference, to the current object, so if you need to use it with something that expects a value or a reference, then you need to dereference it first. (It’s a wonderfully confusing thing in C++ that in order to use a pointer with something that expects a reference, the pointer needs to be “dereferenced” first…)

( * ) If you think it makes a copy of the AudioProcessor object or something like that : it doesn’t.


yep, it is simply passing itself to the editor it’s creating so that the editor may make changes to it’s parameters.

As for the dereference pointer to the passed by value, It is a bit funky, but @Xenakios’s response as to why makes sense to me.

1 Like

Thank you guys! You cleared that up for me. Strange thing is that this:
DelayEditor::DelayEditor (DelayAudioProcessor(& owner))

didn’t give me a compiler error. I deleted the unnecessary brackets:
DelayEditor::DelayEditor (DelayAudioProcessor& owner)

Without them the syntax makes sense to me.
Thanks for the discussion!
Cheese, Luke

Yeah unnecessary parentheses often don’t cause compiler errors.