this() in struct
Jonathan M Davis
jmdavisProg at gmx.com
Tue Oct 9 11:17:08 PDT 2012
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
More information about the Digitalmars-d-learn
mailing list