# Vectors of widgets

**URL:** <https://forum.juce.com/t/vectors-of-widgets/29489>\
**Category:** General JUCE discussion\
**Created:** [September 18, 2018, 2:14pm UTC](https://forum.juce.com/t/vectors-of-widgets/29489 "2018-09-18T14:14:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![diaseis](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@diaseis](https://forum.juce.com/u/diaseis)\
**Post date:** [September 18, 2018, 2:14pm UTC](https://forum.juce.com/t/vectors-of-widgets/29489/1 "2018-09-18T14:14:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [September 18, 2018, 2:16pm UTC](https://forum.juce.com/t/vectors-of-widgets/29489/2 "2018-09-18T14:16:32Z")

</div>

`OwnedArray` would be a better option for holding multiple sliders:

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

```

[https://docs.juce.com/master/classOwnedArray.html](https://docs.juce.com/master/classOwnedArray.html)

---

<div class="post-metadata">

**Author:** ![diaseis](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@diaseis](https://forum.juce.com/u/diaseis)\
**Post date:** [September 18, 2018, 2:17pm UTC](https://forum.juce.com/t/vectors-of-widgets/29489/3 "2018-09-18T14:17:45Z")

</div>

Thank you very much !

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [September 18, 2018, 2:24pm UTC](https://forum.juce.com/t/vectors-of-widgets/29489/4 "2018-09-18T14:24:33Z")

</div>

N.B. that [OwnedArray::add()](https://docs.juce.com/develop/classOwnedArray.html#a71587e33a86ec14556128e162470319f) returns the added element as pointer, so you don’t need the ugly .getLast() like you have to do in std::vector:

```auto
OwnedArray<Slider> mySliders;

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

```

or even:

```auto
OwnedArray<Slider> mySliders;

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

```

---

<div class="post-metadata">

**Author:** ![diaseis](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@diaseis](https://forum.juce.com/u/diaseis)\
**Post date:** [September 18, 2018, 2:26pm UTC](https://forum.juce.com/t/vectors-of-widgets/29489/5 "2018-09-18T14:26:13Z")

</div>

Nice ! thx a lot
