mashu
October 29, 2015, 6:09am
1
hopefully a simple question: What's the syntax for making, (and then retrieving from) an Array of StringArrays?
for example, i have the following StringArrays:
const StringArray alphabetFruit = {"apple", "banana", "cherry" ...};
const StringArray alphabetAnimals = {"ape", "bear", "cow" ...};
const StringArray alphabetCountries = {"Algeria", "Botswana", "Columbia" ...};
How can i put them all in a parent array (or probably OwnedArray) called 'alphabets' ??
I think it's roughly the syntax:
const StringArray alphabetFruit = {"apple", "banana", "cherry" ...};
const StringArray alphabetAnimals = {"ape", "bear", "cow" ...};
const StringArray alphabetCountries = {"Algeria", "Botswana", "Columbia" ...}
Array<const StringArray> alphabets;
alphabets.insert(0, alphabetFruit);
alphabets.insert(1,alphabetAnimals);
etc..
Apologies if this is misleading, beginner myself!
mashu
October 29, 2015, 11:33am
3
Thanks, yeah that's basically what i did....i used 'add', but it seems like it might have worked the same.
so...umm,,,
how to read???
jules
October 29, 2015, 11:54am
4
Thanks to C++11 you can just write stuff like this:
Array<StringArray> foo { StringArray { "abc", "def" },
StringArray { "abdfdfg", "sdfsgdsf", "aasdfsd" } };
mashu
October 29, 2015, 1:01pm
5
is getting "sdfsdsf" as simple as foo[1][1] ?
jules
October 29, 2015, 1:47pm
6
That'd be very inefficient, but would work. Most efficient would be foo.getReference (0)[0]
mashu
October 29, 2015, 2:18pm
7
it's a rare call to update the GUI when a selected instrument is changed. I think i'll go with simplicity and readable code, over efficiency in this case. ;)
cheers
daniel
October 29, 2015, 2:36pm
8
It's not only efficency, the Array operator [] returns a copy of the element. So the complete StringArray would be copied, just to access one element.
If you use now the operator to manipulate an element, you even update the copy, which is discarded in the next line of code anyway.
E.g.
foo[0].add ("Another"); // will leave foo unchanged
foo.getReference(0).add("Another"); // will do what you expect.
I seeked for the problem a whole day, so I hope I could save you that time
Have fun...
1 Like