Vectors of widgets

Hello,
I’m very new to all of this so I am sorry if this is completely obvious but still, I miss it.

I want to create a vector of sliders in order to make a simple step sequencer. However, this line of code generates an error :

midiVolStep.push_back(initSlider);

I get the error :

Error	C2248: 'juce::Slider::Slider' : impossible to access a private member declared int the class 'juce::Slider' (compilation of source file ..\..\Source\PluginEditor.cpp)	

I’m compiling with VS Community 2017

Thank you (and sorry if this question is stupid) :slight_smile:

OwnedArray would be a better option for holding multiple sliders:

OwnedArray<Slider> mySliders;
mySliders.add(new Slider());
addAndMakeVisible(mySliders.getLast());

https://docs.juce.com/master/classOwnedArray.html

Thank you very much !

N.B. that OwnedArray::add() returns the added element as pointer, so you don’t need the ugly .getLast() like you have to do in std::vector:

OwnedArray<Slider> mySliders;

auto* slider = mySliders.add(new Slider());
addAndMakeVisible (slider);

or even:

OwnedArray<Slider> mySliders;

addAndMakeVisible (mySliders.add (new Slider()));
1 Like

Nice ! thx a lot