this() in struct

Zhenya zheny at list.ru
Tue Oct 9 12:00:30 PDT 2012


On Tuesday, 9 October 2012 at 19:04:40 UTC, Jonathan M Davis 
wrote:
> On Tuesday, October 09, 2012 20:09:56 Zhenya wrote:
>> Ok.Then can I do my own .init property that can be executed in
>> compile-time?
>
> No. You directly initialize the member variables to what you 
> want them to be,
> and that's the values that they have in the init property. You 
> can't have
> anything like a function or constructor to initialize them all 
> together.
> However, you _can_ use the results of functions to initialize 
> the member
> variables if the functions will work at compile time. e.g.
>
> struct S
> {
>  int i = foo();
>  string s = bar("joe");
> }
>
> int foo()
> {
>  return 7;
> }
>
> string bar(string str)
> {
>  return str ~ " schmoe";
> }
>
> assert(S.init == S(7, "joe schmoe"));
>
> - Jonathan M Davis

Understood.Thank you very much guys =)




More information about the Digitalmars-d-learn mailing list