SliderAttachment and OwnedArray

Hi there,

I will have a bunch of sliders stored via

OwnedArray<Slider> sliderArray;
for (int i = 0; i<NS; i++) {
sliderArray.add(new juce::Slider())}

and then later I will create attachments via

StringArray sliderIDArray;
OwnedArray<AudioProcessorValueTreeState::SliderAttachment> sliderAttachmentArray;
for (int i = 0; i<NS; i++) {
sliderIDArray.add("slider_" + juce::String(i));
sliderAttachmentArray.add(new AudioProcessorValueTreeState::SliderAttachment(myValueTreeState, sliderIDArray[i], *sliderArray[i]))}

Here is my issue/question:
Since it is not possible to use regular std containers for sliders (or other juce components for that matter), I need to use OwnedArray. But this class stores pointers, and the constructor of SliderAttachment actually has Slider& as its third argument. If I dereference the pointer via


I feel I will be creating a copy and things won’t work.

Am I doing things wrong?

Dereferencing a pointer results in a reference, not a copy. So that’s totally fine.

Thanks for the response.
I was definitely having issues with std::vector<juce::Slider>, please see:

I ended up using juce::OwnedArray<juce::Slider> to avoid problems.