oop tutorials

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Mar 4 05:57:20 PST 2008


"Saaa" <empty at needmail.com> wrote in message 
news:fqjjn5$2jb6$1 at digitalmars.com...
>> may be this?
>>
>> Class[] className;
>> className.length=10;
>> className[0]=new Class();
>> className[0].function;
>>
>
> Yes it is :)
>
> What then does Class[] className do exactly? Or, why do I need to use new?
>

The same reason:

Class class;
class.function;

doesn't work.  Because all class variables are references which point to 
nothing until you use 'new'.

A Class[] is an array of references to class instances which is filled with 
nulls by default.  You have to actually initialize the array by creating 
instances of the class.

Class[] arr;

foreach(ref c; arr)
    c = new C; 




More information about the Digitalmars-d-learn mailing list