initialization of structs
Christian Köstlin
christian.koestlin at gmail.com
Mon Sep 26 21:37:08 PDT 2011
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
More information about the Digitalmars-d-learn
mailing list