digitalmars.D.learn - how do I create an array of objects as member of class?
- Assembly (18/18) Jun 26 2015 Imaginary code:
- Adam D. Ruppe (5/10) Jun 26 2015 Keep in mind that those instances are *static* and probably not
- Assembly (5/15) Jun 29 2015 I wasn't aware about this. I'm used to have static only when I
Imaginary code: class Foo { } class Baa { Foo a = new Foo(); Foo b = new Foo(); Foo[] l = [a,b]; } What should I use instead of to it work? Array!Foo(a,b) didn't worked either. I know this works: class Baa { Foo a = new Foo(); Foo b = new Foo(); Foo[] l; this() { l = [a,b]; } But I'd like to initializa it at declaration time
Jun 26 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.
Jun 26 2015
On Friday, 26 June 2015 at 22:14:56 UTC, Adam D. Ruppe wrote:On Friday, 26 June 2015 at 21:50:30 UTC, Assembly wrote:I wasn't aware about this. I'm used to have static only when I request so, like using static keyword in each member that must be static. Gonna move it to the constructor.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.Gonna do so, thanksI know this works:Doing it in the constructor is really the best way.
Jun 29 2015