On 9/26/11 23:18 , Andrej Mitrovic wrote:
You can hide the constructor from external code by using "private
this()". And you can disable the default constructor via @disable
this();
You may also wish to make your fields private as well.

You don't necessarily have to make createS() a free function, you can
make it a static function inside of S, ala:

struct S {
     @disable this();
     static S create(int _i) { return S(_i); }
private:
     int i;
     this(int i_) { i = i_; }
}

create() will not occupy any space in any of the S instances. If that
doesn't compile it's because I haven't had my coffee yet. :p
very good ... exactly what I wanted :)
thanks a lot!

christian

Reply via email to