oop tutorials
Saaa
empty at needmail.com
Tue Mar 4 06:03:15 PST 2008
Thanks,
Why isn't it initialized?
I mean, when are these null referenced class pointers useful?
>>> 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