# Store custom Component into Vector

**URL:** <https://forum.juce.com/t/store-custom-component-into-vector/14702>\
**Category:** General JUCE discussion\
**Created:** [April 28, 2015, 4:05am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702 "2015-04-28T04:05:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jordan\_Harris](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jordan\_Harris](https://forum.juce.com/u/Jordan_Harris)\
**Post date:** [April 28, 2015, 4:05am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/1 "2015-04-28T04:05:51Z")

</div>

Hello, I'm trying to store a custom class that I made (called Circle), which inherits from Component, into a vector so I can draw a collection of circles all over the screen and erase them. I want to add the with push\_back() and erase with pop\_back. I'm only overriding the paint() method. I'm getting a compile every when I try to use push\_back though and I can't seem to figure out how to do it.  
  
Here's the error:

Error&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp; error C2248: 'juce::Component::Component' : cannot access private member declared in class 'juce::Component' (..\..\Source\MainComponent.cpp)&nbsp;

&nbsp;

Here's the class:

&nbsp;

```
class Circle : public Component 
{ 
public: 
Circle(const float x, const float y, const float radius, const Colour colour); 
void paint (Graphics&); 

private: 
    float m_x; 
    float m_y; 
    float m_radius; 
    Colour m_colour; 
    float m_diameter; 
}; 

Circle::Circle(const float x, const float y, const float radius, const Colour colour) 
    :m_x{ x }, m_y{ y }, m_radius{ radius }, m_colour{ colour } 
{ 
    m_diameter = m_radius * 2;
} 

void Circle::paint(Graphics& g) 
{
    g.setColour(m_colour); 
    g.fillEllipse(m_x, m_y, m_diameter, m_diameter); 
}
```

&nbsp;

And I'm just trying to use it something like this:

```
vector<Circle> circles;
```

```
circles.push_back(Circle{ x, y, 10.0f, red });
```

&nbsp;

I'm sure there's a much better way of doing this, but I'm new to JUCE and this is similar to the way I did it in Cinder. If anyone knows how to fix this, or even a better way of doing this I would be really grateful. Idk why I can't get this to work. I don't know if I should even be inheriting from Component.

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![Jordan\_Harris](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jordan\_Harris](https://forum.juce.com/u/Jordan_Harris)\
**Post date:** [April 28, 2015, 6:43am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/2 "2015-04-28T06:43:10Z")

</div>

Actually, I just didn't inheret from anything and I got it working. I guess that'll work for what I'm wanting to do. :)

---

<div class="post-metadata">

**Author:** ![Jordan\_Harris](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jordan\_Harris](https://forum.juce.com/u/Jordan_Harris)\
**Post date:** [April 28, 2015, 6:56am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/3 "2015-04-28T06:56:00Z")

</div>

I'm still curious if you can create and store components in an array though. I'd like to create an array of circles then somehow move those circles around by clicking + dragging them.&nbsp;

---

<div class="post-metadata">

**Author:** ![Pca](https://avatars.discourse-cdn.com/v4/letter/p/7ba0ec/32.png) [@Pca](https://forum.juce.com/u/Pca)\
**Post date:** [April 28, 2015, 7:05am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/4 "2015-04-28T07:05:43Z")

</div>

Well.... just try this to call the constructor instead of loading directly the private members, it should work better :-)

```
circles.push_back(Circle ( x, y, 10.0f, red ) );
```

But anyway you should consider using Juce's Array or OwnedArray instead of stdlib members. Take time having a look at the complete Juce object model, you'll find a lot of useful things that will simplify your life ;-)

&nbsp;

/Phil

---

<div class="post-metadata">

**Author:** ![Jordan\_Harris](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jordan\_Harris](https://forum.juce.com/u/Jordan_Harris)\
**Post date:** [April 28, 2015, 7:18am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/5 "2015-04-28T07:18:54Z")

</div>

Thanks for replying man. I'll have to check out JUCE's arrays and other data structures. This is just practice anyways. I'm trying to learn as much about JUCE as I can and I thought this would be a good exercise.&nbsp;

---

<div class="post-metadata">

**Author:** ![Jordan\_Harris](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jordan\_Harris](https://forum.juce.com/u/Jordan_Harris)\
**Post date:** [April 28, 2015, 7:47am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/6 "2015-04-28T07:47:06Z")

</div>

What do you know, Getting Started With JUCE has 2 sections on storing components in the JUCE Array and OwnedArray classes. Man, I feel dumb for not noticing that. Now I should be able to figure that out. :) That's in chapter 3 if anyone else needs this.

---

<div class="post-metadata">

**Author:** ![nicolasdanet](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicolasdanet/32/56_2.png) [@nicolasdanet](https://forum.juce.com/u/nicolasdanet)\
**Post date:** [April 28, 2015, 9:38am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/7 "2015-04-28T09:38:00Z")

</div>

Component is NOT copyable (and AFAIK not movable)?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 28, 2015, 9:42am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/8 "2015-04-28T09:42:06Z")

</div>

No - how could it be copyable!? If you copy it, what would happen to its child components or parent component? What about all the listeners that are attached? etc etc!

---

<div class="post-metadata">

**Author:** ![nicolasdanet](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicolasdanet/32/56_2.png) [@nicolasdanet](https://forum.juce.com/u/nicolasdanet)\
**Post date:** [April 28, 2015, 9:47am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/9 "2015-04-28T09:47:00Z")

</div>

Hey Jules, it was not a question. It was just a suggestion to the OP why using a vector of Components is not a good idea. Of course it can not be copied 😉

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 28, 2015, 9:47am UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/10 "2015-04-28T09:47:29Z")

</div>

Sure :)

I was just confirming why that's the case, for anyone who might have been reading and not seeing why that is.

---

<div class="post-metadata">

**Author:** ![Jordan\_Harris](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jordan\_Harris](https://forum.juce.com/u/Jordan_Harris)\
**Post date:** [April 28, 2015, 6:42pm UTC](https://forum.juce.com/t/store-custom-component-into-vector/14702/11 "2015-04-28T18:42:06Z")

</div>

i had a feeling that's what it was. Thanks for replying everyone. I'm still figuring out how components work. I love how helpful this forum is. Sorry for all the noob questions. I try to only ask if I can't find the answer.
