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);
}
---

Reply via email to