> I am confused as to why the first way would be incorrect, for what we are trying to do.
The first creates two different objects for each value, one of which is a non-modifiable copy of the other.
The second does not create another object; a reference is just an alias.
The first will not be incorrect for what we are trying to do. Because:
-- the variables are not expected to be modified after
initialise_vars() is called.
--
double is a copyable type (unlike, say, an array or a stream).
--
double is inexpensive (small footprint and trivial copy, unlike, say, a vector).
-- initialisation of a second object does not have external side effects (like, say, appending a record to a file).
> the const definitions are outside the namespace scope,
The const definitions are outside the unnnamed namespace; but they are still at namespace scope.
At the global namespace scope.
The outermost declarative region of a translation unit is also a namespace, called the global namespace.
A name declared in the global namespace has global namespace scope (also called global scope). |