{Please try to quote only the minimum that provides enough context. -mod}
alex wrote:
It is most certainly of no use to hardcode these values into
constructor, but it compiles :)
Static integral constants, however may be initialized in the class
declaration like this:
class Statics
{
static int const g_one = 1;
};
Though I agree with the sentiment, about avoiding actual
numbers to appear in the code, I must point out that the
above exhibits another of the "big mistakes" from the
point of view of "quality code" -- similar to putting a
comment like this:
a = 1; // assign 1 to a
What I'm saying is that the name g_one says absolutely
nothing more than 1 says; it is exactly equivalent to
type 1 as it is to spell it out; and the benefit that
if the number you need ever changes you can adjust it
easily is moot -- I would definitely find it horrendous
to ever stumble into a program that says:
const int g_one = 2;
What I'm saying is: if that 1 is supposed to be the
number of elements, then call it number_of_elements (or
equivalent); if it is supposed to be the maximum size
allowed, call it max_allowed, or max_size_allowed, or
max_size .... etc. etc.
Sorry, Carlos, but I have to disagree. Consider a mathematical equation
with a constant g (sub) 1. How else would you describe it? Further,
[ comp.lang.c++.moderated. First time posters: Do this! ]