[chuck-users] Doing something to all members of a class?
signal.automatique at gmail.com
Mon Mar 12 21:43:30 EDT 2007
I'm having a bit of a issue with classes.
Say I have a class that has a member that's simply a integer used for
I'll have a few instances (ten or so) and they will all be counting their
own little thing on their own. So far so good. Now something happens and I'd
like to reset all the counters to zero after which they should be
How to go about this in a efficient way?
I tried writing a static function to do this but it seems I misunderstand
static functions. I thought that if I'd call a static function as a member
of the class (not of a particular instance) then this function would be
executed for all instances. That turns out not to be true; it only gets
executed a single time. To make it more confusing (to me) referencing
non-static int member of the class inside of a static function makes ChucK
die while complaining about a nullpointer exception. In fact it will also
die if I call the same function as a member of a particular instance. When I
reference the number as "this.my_number" instead of just as "my_number"
ChucK is a bit nicer about it and informs that "this" isn't allowed in
static functions and refuses to run at all (better then suddenly dieing with
My attempt to figure out what's going on;
fun static void bar()
1 => A.my_number;
2 => B.my_number;
//here we die
"A.bar();" as a last line would also make ChucK die, BTW.
Is this a bug (the nullpointer, I mean)? Am I completely misunderstanding
static functions? Is the only way to go about this to make a array of type
Foo and loop over it going "0 => ArrayOfFoos[n].my_number" or something to
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the chuck-users