How about adding a polymorphic array of references?


My “other” language - REALbasic ( maybe C# and too ) allows one to treat arrays of object references polymorphicaly.

For example If class B inherits from class A - i can write the following code:

dim arrayB() As B
dim arrayA() as A

for i as integer = 0 to 10
arrayB.append new B()

arrayA = arrayB.

I could also write a method that takes an array of references to B and returns it directly as an array of type A.

Now i have no idea how this is done “under the hood” but it is a very useful thing to have in ones “arsenal”

Any chance this could be done in a future version of the JUCE arrays ?

Incidentally I have made my own extensions of some JUCE container/array classes to allow for arrays to be passed around by reference :

This is all so i can emulate the way reference counting works in REALbasic ( or for that matter )

#define REF(T) ReferenceCountedObjectPtr

#define ARRAYINTRINSIC(T) IntrinsicArrayReferenceCountedObject< T >
#define ARRAYOBJECT(T) ReferenceCountedArrayObject< T >
#define ARRAYSTRING StringArrayReferenceCountedObject


class MemoryBlockJ : public MemoryBlock, public ReferenceCountedObject


class IntrinsicArrayReferenceCountedObject : public Array, public ReferenceCountedObject

class StringArrayReferenceCountedObject : public StringArray, public ReferenceCountedObject

class ReferenceCountedArrayObject : public ReferenceCountedArray, public ReferenceCountedObject

 //   Debugger();



Sorry, I thought the ReferenceCountedArray would already do that. Very easy to fix, I’ll tweak it.


You’re a star !.


oh did you mean the polymorphic bit or just modding your current array templates to inherit from ReferenceCountedObject ?


I meant the polymorphic bit. You can now do:

ReferenceCountedArray<A> a; ReferenceCountedArray<B> b (a); a = b;