# Array of CodeDocuments?

**URL:** <https://forum.juce.com/t/array-of-codedocuments/12124>\
**Category:** General JUCE discussion\
**Created:** [January 1, 2014, 7:57pm UTC](https://forum.juce.com/t/array-of-codedocuments/12124 "2014-01-01T19:57:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimspree](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@jimspree](https://forum.juce.com/u/jimspree)\
**Post date:** [January 1, 2014, 7:57pm UTC](https://forum.juce.com/t/array-of-codedocuments/12124/1 "2014-01-01T19:57:09Z")

</div>

Does anyone know why its not possible to create an Array of CodeDocuments? When trying to compile this:

```
Array<CodeDocument> arrayOfDocs;

CodeDocument doc;

arrayOfDocs.add(doc);
```

I get: Call to deleted constructor of 'juce::CodeDocument' from with the below line of the array add function:

```
new (data.elements + numUsed++) ElementType (newElement);
```

---

<div class="post-metadata">

**Author:** ![jimspree](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@jimspree](https://forum.juce.com/u/jimspree)\
**Post date:** [January 1, 2014, 8:20pm UTC](https://forum.juce.com/t/array-of-codedocuments/12124/2 "2014-01-01T20:20:44Z")

</div>

Seems that this is due to the CodeDocument not having an copy constructor and not getting one due to:

```
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CodeDocument)
```

being defined in its declaration... I guess there is a good reason for that, otherwise Jules would not put it in. I guess I could wrap the code document by another class with something hacky in it:

```
class CodeDocument2

        {

        public:

            CodeDocument2() {};

            CodeDocument2(CodeDocument2 const &ref)

            {

                doc.replaceAllContent(ref.doc.getAllContent());

            };

            CodeDocument doc;

        };
```

Will keep thinking about if what I'm doing is the right approach anyways though.&nbsp;

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [January 1, 2014, 9:21pm UTC](https://forum.juce.com/t/array-of-codedocuments/12124/3 "2014-01-01T21:21:59Z")

</div>

Have you tried using an OwnedArray ?

Rail

---

<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:** [January 1, 2014, 10:49pm UTC](https://forum.juce.com/t/array-of-codedocuments/12124/4 "2014-01-01T22:49:48Z")

</div>

Yes, OwnedArray would be the one to use. Array is designed for classes that have by-value semantics, and something like a CodeDocument definitely isn't a pass-by-value object!

---

<div class="post-metadata">

**Author:** ![jimspree](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@jimspree](https://forum.juce.com/u/jimspree)\
**Post date:** [January 2, 2014, 8:58am UTC](https://forum.juce.com/t/array-of-codedocuments/12124/5 "2014-01-02T08:58:49Z")

</div>

Thanks guys! I was thinking the same thing last night when I decided to step away from the project, and funny enough I was using an owned array in the same class.&nbsp;
