Static Constructors

Jarrett Billingsley jarrett.billingsley at gmail.com
Fri Oct 3 15:12:31 PDT 2008


On Fri, Oct 3, 2008 at 5:57 PM, Saaa <empty at needmail.com> wrote:
> I've been using classes for a few months now and I keep on making arrays of
> instances like:
>
> class Fruit
> {
> this( parameters )
> {
> }
> ..
> }
>
> Fruits fruit[];
>
> void init()
> {
> fruit.length=fruit.length+1; // annoys me :)
> fruit[$]=new Fruit(  .. );
> }

Have you heard of the append operator?

fruit ~= new Fruit(...);

>
> deleting is even more annoying.

You don't have to delete anything.  This is what the GC is for.

>
> Now I've been reading about static constructors and is that somehow a
> solution to this manual array management?

I don't know what you're trying to do, so it may or may not be a solution.


More information about the Digitalmars-d-learn mailing list