struct inheritance need?
Weed
resume755 at mail.ru
Thu Dec 18 04:43:27 PST 2008
Kagamin пишет:
> Weed Wrote:
>
>> Kagamin пишет:
>>> Weed Wrote:
>>>
>>>>> Global variables are static members of module, wich is similar to
>>>>> class and also has static constructor.
>>>> So what?
>>> So your problem is solved.
>> If everything was so simple! :)
>>
>> Once again: the static constructor of class NOT constructs an object.
>
> Static constructor can execute any valid D statements including construction of objects.
The static constructor does not take *this*. Therefore, it can not
create instance of object. In your case it initiates the external variable.
> This works:
> ---
> import std.stdio;
>
> class Matrix
> {
> int i;
>
> this(int j)
> {
> i=j;
> }
> }
>
> Matrix m;
>
> static this()
> {
> m=new Matrix(7);
> }
>
> void main()
> {
> writeln(m.i);
> }
> ---
More information about the Digitalmars-d-learn
mailing list