Re: static data in a sub-class

2012-12-23 Thread Steve D
class Monster :Creature { static float[3] hi = 1; this(float[] x=null) {if (x) hi = x;} That is a bad idea. x is passed to a single Monster object but the 'hi' static member of the whole Monster class gets affected. Just because there is a SwiftMonster, all Monsters become swift. Yep I know

Re: static data in a sub-class

2012-12-23 Thread Ali Çehreli
On 12/23/2012 02:08 PM, Steve D wrote: > Let's say it's a game and the objects are creatures. Thanks for giving more context. It helps to see meaningful names to understand code better. > class Creature { > abstract void move(); > } That's very reasonable. > class Monster :Creature { > stat

Re: static data in a sub-class

2012-12-23 Thread Steve D
Thanks Ali, I'm still playing with your earlier suggestion of passing the array to A in a super() call from B. But now... I dunno things are getting worse... it 'sometimes' works see below.. While we're chatting, I've slightly added to the earlier example to better replicate my actual code.

Re: static data in a sub-class

2012-12-22 Thread Ali Çehreli
On 12/22/2012 01:37 PM, Steve D wrote: > I will continue playing with your suggestions etc to see > what's cleanest. Both of those options have unnecessary costs. If everything is known at compile time, you can use the curiously recurring template pattern: import std.stdio; class A(SubT) {

Re: static data in a sub-class

2012-12-22 Thread Steve D
On Saturday, 22 December 2012 at 21:14:58 UTC, Ali Çehreli wrote: On 12/22/2012 12:44 PM, Steve D wrote: Hello, How can I get class B's array printed, using inherited A's function? (Dmd 2.060) class A { static float[3] hi = 1; void f() { writefln("hi %s",hi); } } class B : A { static float[

Re: static data in a sub-class

2012-12-22 Thread Steve D
On Saturday, 22 December 2012 at 21:04:47 UTC, Jonathan M Davis wrote: On Saturday, December 22, 2012 21:44:33 Steve D wrote: Hello, How can I get class B's array printed, using inherited A's function? (Dmd 2.060) class A { static float[3] hi = 1; void f() { writefln("hi

Re: static data in a sub-class

2012-12-22 Thread Ali Çehreli
On 12/22/2012 12:44 PM, Steve D wrote: Hello, How can I get class B's array printed, using inherited A's function? (Dmd 2.060) class A { static float[3] hi = 1; void f() { writefln("hi %s",hi); } } class B : A { static float[3] hi = 2; } B b = new B(); b.f(); // prints 'hi [1,1,1]' // can I g

Re: static data in a sub-class

2012-12-22 Thread Jonathan M Davis
On Saturday, December 22, 2012 21:44:33 Steve D wrote: > Hello, > How can I get class B's array printed, using inherited A's > function? (Dmd 2.060) > > class A { > static float[3] hi = 1; > > void f() { writefln("hi %s",hi); } > } > > class B : A { > st

static data in a sub-class

2012-12-22 Thread Steve D
Hello, How can I get class B's array printed, using inherited A's function? (Dmd 2.060) class A { static float[3] hi = 1; void f() { writefln("hi %s",hi); } } class B : A { static float[3] hi = 2; } B b = new B(); b.f(); // prints 'hi [1,1,