style question on structs
Jonathan
jdgall84 at gmail.com
Sun Dec 29 10:58:05 PST 2013
Given a struct
struct Foo{
enum INT_C {Yes, No}
INT_C a;
}
-- we wish to make a constructor. We want to set the answer to
Yes if we construct the struct with an integer. There are some
stylistic choices to be made.
The first choice is: do we use this (I seem to recall being told
in Java with classes there is debate whether 'this' is
preferrable or not).
this(int y)
{
//choice 1:
this.a = this.INT_C.Yes;
//choice 2:
a = INT_C.Yes;
}
The second choice is: do we qualify by the struct name:
this(int y)
{
//option 1
a = Foo.INT_C.Yes;
//option 2
a = INT_C.Yes;
}
The reason I ask, is that I remember some cases in Java where it
was advantageous to use 'this'.
More information about the Digitalmars-d-learn
mailing list