# 'Array' in 'Array' of clases 'add' not working

**URL:** <https://forum.juce.com/t/array-in-array-of-clases-add-not-working/22972>\
**Category:** General JUCE discussion\
**Created:** [June 18, 2017, 8:21am UTC](https://forum.juce.com/t/array-in-array-of-clases-add-not-working/22972 "2017-06-18T08:21:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dibla](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dibla](https://forum.juce.com/u/dibla)\
**Post date:** [June 18, 2017, 8:21am UTC](https://forum.juce.com/t/array-in-array-of-clases-add-not-working/22972/1 "2017-06-18T08:21:52Z")

</div>

Am an idiot, or is it an error?

Why ‘Array::add()’ not working?

code:

```
class Test
{
public:
	class Serie
	{
		int n = 0;
        public:
		Array<Point<int>> values;
	};

	Test() {}

	~Test() {}

	std::vector<Serie> stdArraySeries;	// std vector
	Array<Serie> juceArraySeries; // JUCE array

private:
	JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Test)
};

class MainContentComponent : public Component
{
public:
	MainContentComponent()
	{
            /// Testing std::vector
	   test.stdArraySeries.push_back(Test::Serie()); // Add 'Serie' to std::vector
	   test.stdArraySeries[0].values.add({ 1, 2 }); // Add 'Point' to 'values' in 'Serie'
	   int count1 = test.stdArraySeries[0].values.size();	// count1 == 1 (O.K.)

            /// Testing JUCE Array
	   test.juceArraySeries.add(Test::Serie()); // Add 'Serie' to JUCE 'Array'
	   test.juceArraySeries[0].values.add({ 1, 2 }); // Add 'Point' to 'values' in 'Serie'
           int count2 = test.juceArraySeries[0].values.size();	// count2 == 0 (??????????????????????)
	}

	~MainContentComponent() {}

private:
	Test test;
	JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainContentComponent)
};

```

‘count1’ is ‘1’ (O.K.)  
‘count2’ is ‘0’ (bad ☹ )

---

<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:** [June 18, 2017, 9:31am UTC](https://forum.juce.com/t/array-in-array-of-clases-add-not-working/22972/2 "2017-06-18T09:31:40Z")

</div>

The juce Array::operator method is different from std::vector because it returns its result by _value_, not by reference. So you’re modifying a temporary value.

---

<div class="post-metadata">

**Author:** ![dibla](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dibla](https://forum.juce.com/u/dibla)\
**Post date:** [June 18, 2017, 10:22am UTC](https://forum.juce.com/t/array-in-array-of-clases-add-not-working/22972/3 "2017-06-18T10:22:15Z")

</div>

> [@jules](#):
>
> The juce Array::operator method is different from std::vector because it returns its result by value, not by reference. So you’re modifying a temporary value.

I already understand. Thanks.
