# std::vector\<juce::Label\> Error

**URL:** <https://forum.juce.com/t/std-vector-juce-label-error/53712>\
**Category:** General JUCE discussion\
**Created:** [November 12, 2022, 7:40pm UTC](https://forum.juce.com/t/std-vector-juce-label-error/53712 "2022-11-12T19:40:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![baintonaj](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@baintonaj](https://forum.juce.com/u/baintonaj)\
**Post date:** [November 12, 2022, 7:40pm UTC](https://forum.juce.com/t/std-vector-juce-label-error/53712/1 "2022-11-12T19:40:01Z")

</div>

Hi, I am trying to create a `std::vector` for an unknown number of `juce::Label`s that is selectable at runtime between 1 and 10. I keep trying to create something like the following in a basic GUI application. I’m not sure why Xcode 11.3.1 (macOS Mojave 10.14.6) is giving me the error: `Call to deleted constructor of 'juce::Label'`. It seems a `std::vector<juce::Label>` does not behave the way I would expect for a `std::vector<float>` to behave, for example. Any insights are appreciated! Thanks for your help.

```
// MainComponent.h
private:
    juce::Label temp_label;
    std::vector<juce::Label> label_vec;

// MainComponent.cpp
// MainComponent::paint()

// 'num_labels' is a size_t selected from 1 to 10 
while (label_vec.size() > num_labels) {
	label_vec.pop_back();
}

for (size_t i {0}; i < num_labels; ++i) {
    label_vec.push_back(temp_label); // ERROR: Call to deleted constructor of 'juce::Label'

    label_vec[i].setText("0.0", juce::dontSendNotification);	    
    label_vec[i].setFont(juce::Font (20.0, juce::Font::plain));
    label_vec[i].setColour(juce::Label::textColourId, juce::Colours::white);
    label_vec[i].setJustificationType(juce::Justification::centred);
    addAndMakeVisible(label_vec[i]);
}

```

---

<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:** [November 12, 2022, 8:14pm UTC](https://forum.juce.com/t/std-vector-juce-label-error/53712/2 "2022-11-12T20:14:58Z")

</div>

`std::vector` requires elements to be movable or copyable.

`juce::Label` is explicitly made non-copyable by the `JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR` macro. It’s also implicitly non-movable since it doesn’t define a move constructor.

That macro actually makes it tricky to comply with [this cpp core guidelines rule](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-five) about the rule of 5.

It’d be nice if the JUCE team added move constructors for things that are using that macro - or better yet, deprecate the macro and properly follow the guideline by explicitly defining copy and move constructors.

* * *

If you want a dynamic list of components, you could use `std::vector<std::unique_ptr<juce::Label>>`, or `juce::OwnedArray<juce::Label>`.

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [November 12, 2022, 8:42pm UTC](https://forum.juce.com/t/std-vector-juce-label-error/53712/3 "2022-11-12T20:42:25Z")

</div>

I would be in favor of different macros for copy and move operations:

- JUCE\_NON\_COPYABLE
- JUCE\_NON\_MOVABLE
- JUCE\_DEFAULT\_COPYABLE
- JUCE\_DEFAULT\_MOVABLE
- JUCE\_CONSTEXPR\_COPYABLE
- JUCE\_CONSTEXPR\_MOVABLE

---

<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:** [November 12, 2022, 9:19pm UTC](https://forum.juce.com/t/std-vector-juce-label-error/53712/4 "2022-11-12T21:19:44Z")

</div>

I think it is the same if you write

```auto
JUCE_DEFAULT_COPYABLE (Foo)
// or
Foo (const Foo&) = default;

```

It would only save typing if you create all five with one macro…

We have to remember, the `=default` or `=delete` syntax wasn’t available when those macros were written. Nowadays I find little use in adding those shortcuts…

Unless you want to allow to globally override it, but that would be nasty 😉

---

<div class="post-metadata">

**Author:** ![baintonaj](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@baintonaj](https://forum.juce.com/u/baintonaj)\
**Post date:** [November 12, 2022, 9:33pm UTC](https://forum.juce.com/t/std-vector-juce-label-error/53712/5 "2022-11-12T21:33:16Z")

</div>

Thank you all! I really appreciate your help!

---

<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:** [November 12, 2022, 9:37pm UTC](https://forum.juce.com/t/std-vector-juce-label-error/53712/6 "2022-11-12T21:37:05Z")

</div>

One thing JUCE does _not_ need is more macros 😛
