* Andrew Chalk:
I have a variable that is initialized with a value read from a configuration
file. Once initialized, it should not be changed anywhere in my program.
What is the best way to enforce this (it should be treated as const)?
Ideally, I would like a violation to generate a compile-time error.
In addition to Ian Collins' reply, you can do
Type const myVariable = valueFromConfigFile();
which for purposes of handling exceptions etc. you can put inside a
function, with lazy initialization (singleton pattern)
Type const& value()
{
static Type const theValue = valueFromConfigFile();
return theValue;
}
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?