struct inheritance need?

naryl cyNOSPAM at ngs.ru
Thu Dec 18 05:00:16 PST 2008


Kagamin Wrote:
> Static constructor can execute any valid D statements including construction of objects.
> 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);
> }
> ---

I think the problem with that is that if you have a lot of functions every one of which needs a static instance of the same class you'll need to maintain a list of static objects in the static constructor. Weed wants every object to be declared in the function where it is needed.


More information about the Digitalmars-d-learn mailing list