Arrays of Unions of Classes?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 6 11:09:49 PST 2015


On 02/06/2015 10:55 AM, DLearner wrote:

 > I can have linear access to classes of different types

To be pedantic, you mean *objects* of different types. (Class is the type.)

 > Because classes are reference types, does that mean a union or an
 > array would only hold a reference to that class?

Yes.

 > Is there a way for them to be squished up next to each other in
 > a way that'd make iterating over them efficent?

I have an example of doing exactly that on a single hierarchy here:

   http://ddili.org/ders/d.en/memory.html#ix_memory.emplace,%20class

As seen in that example, you still need to walk through references to 
the actual objects.

If your classes do not belong to the same hierarchy then you have to 
maintain some kind of type identification yourself.

Ali



More information about the Digitalmars-d-learn mailing list