how do I create an array of objects as member of class?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 26 15:14:54 PDT 2015


On Friday, 26 June 2015 at 21:50:30 UTC, Assembly wrote:
> class Baa {
>   Foo a = new Foo();
>   Foo b = new Foo();
>   Foo[] l = [a,b];

Keep in mind that those instances are *static* and probably not 
what you expect; modifying a will be seen across all instances of 
Baa unless you actually assign it to a new member.

> I know this works:

Doing it in the constructor is really the best way.


More information about the Digitalmars-d-learn mailing list