Hmm, you shouldn&#39;t have to cast from a subclass to its superclass, should you? In this case I&#39;d say that a Bar array extends a Foo array...<div><br></div><div>Maybe what&#39;s going on here is that ChucK determines that the array you try to reference copy into moreFoos consists of solely Bar objects, and therefore it is of the type Bar[]. Maybe ChucK has adopted Java&#39;s type chuck system for generics, meaning you can&#39;t assign a bar array to a Foo array. Why? Because then you would be able to do this:<div>
<br></div><div><div>Bar bars[2];</div><div>bars @=&gt; Foo foos[]; // compile-time error, but let&#39;s say it works anyway</div><div>Spam spam; // extends Foo</div><div>spam @=&gt; foos[0]; // OK, a spam is a foo</div><div>
&lt;&lt;&lt; &quot;Value: &quot;, bars[0].bar &gt;&gt;&gt;; // there&#39;s a spam here, with no bar!</div><div><br></div><div>...which would make no one happy. In Java, for an array, this code will work until spam @=&gt; foos[0], where you&#39;ll get an ArrayStoreException. For a generic type (Java generics are a kind of imitation of C++ templates), you&#39;d get a compile error on the second of my lines above.</div>
<div><br></div><div>BTW, it would be great to have some way of extracting class information from an object in ChucK, similarly to the Class objects in Java. It would be useful for debugging situations like this.</div><div>
<br></div><div>Also, how do you cast arrays? This gives me a syntax error:</div><div><br></div><div>[ bara, barb, barc ] $ Foo[]</div><div><br></div><div>/Stefan</div><div><br></div><div>2009/12/11 Kassen <span dir="ltr">&lt;<a href="mailto:signal.automatique@gmail.com">signal.automatique@gmail.com</a>&gt;</span></div>
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">mike;<br><br><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Why can&#39;t I make an array of a parent type with objects of a single<br>
type, which is a child of the parent?<br><br></blockquote><div><br></div></div><div>Because you forgot to cast. You can cast anything to a type that it extends or that extends it (this includes Object). As long as you keep your inheritance very clean and overload member functions carefully this works fine and shouldn&#39;t damage your sanity.  At least not much. Most of the time.</div>

<div><br></div><div>Yours,</div><div>Kas.</div></div>
<br>_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Release me, insect, or I will destroy the Cosmos!<br>
</div></div>