Array of CodeDocuments?


#1

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

#2

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. 


#3

Have you tried using an OwnedArray ?

Rail


#4

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!


#5

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.