© { JSL }
87
const Fields
·
const
fields are implicitly
static
w
only simple types,
enum
s, &
string
can be
const
w
const
fields require a variable initialiser
w
must be initialized to compile time constant value
struct
Pair
{
private const int
x = 0, y = 0;
}
struct
BadFields
{
... BadFields(...)
{
question = 9 * 6;
}
...
static const int
answer = 42;
...
const int
question;
...
const
Pair origin =
new
Pair();
}
OK
compile time errors
this declares Pair with no instance fields
...
implicitly static
...
can't initialize here
...
not initialized
...
Pair not simple type