initialization of structs

Christian Köstlin christian.koestlin at gmail.com
Mon Sep 26 13:55:46 PDT 2011


Hi,

I have the problem, that I want to always construct a struct with a 
parameter. To make this more comfortable (e.g. provide a default 
parameter I have a factory function to create this struct).

struct S {
   int i;
   this(int i_) { i = i_; }
}

S createS(int i=5) {
   return S(i);
}

My question now is:
Is there a way to enfore the creation of the struct with createS?
Or to put it in another way. Is it possible to forbid something like:
S s; or even auto s = S(1);? I read about the this(this) thing, but that
is only used when the struct is copied, as far as I understood.


(My struct has the nature to only work if it is not constructed with the 
default struct constructor).

thank in advance

christian


More information about the Digitalmars-d-learn mailing list