Hi, list!<br><br>I&#39;m having a bit of a issue with classes.<br><br>Say I have a class that has a member that&#39;s simply a integer used for counting something. <br><br>I&#39;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&#39;d like to reset all the counters to zero after which they should be independant again.
<br><br>How to go about this in a efficient way?<br><br>I tried writing a static function to do this but it seems I misunderstand static functions. I thought that if I&#39;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 &quot;
this.my_number&quot; instead of just as &quot;my_number&quot; ChucK is a bit nicer about it and informs that &quot;this&quot; isn&#39;t allowed in static functions and refuses to run at all (better then suddenly dieing with cryptic complaints!).
<br><br>My attempt to figure out what&#39;s going on;<br>===========================<br><br>class Foo<br>{<br>int my_number;<br><br>fun static void bar()<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &lt;&lt;&lt;my_number&gt;&gt;&gt;;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; 
<br>}<br><br>Foo A;<br>Foo B;<br><br>1 =&gt; A.my_number;<br>2 =&gt; B.my_number;<br><br>&lt;&lt;&lt;&quot;so far&quot;&gt;&gt;&gt;;<br><br>//here we die<br>Foo.bar();<br>======================<br><br>&quot;A.bar();&quot; as a last line would also make ChucK die, BTW.
<br><br>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 &quot;0 =&gt; ArrayOfFoos[n].my_number&quot; or something to that effect?
<br><br>Thanks,<br>Kas.<br>