J
James Kanze
I think I expressed myself very poorly and didn't convey the
proper message.
What I wanted to express was my marvel at such piece of
information about C++ which I didn't know and had never heard
about before. I have been programming C++ for over 15 years,
10 professionally, and I dare to say that I'm pretty fluent
with it, yet I had never heard of this way of
default-initializing a member array in the constructor
initialization list.
The fact that you've been programming C++ for over 15 years may
be the reason. I didn't know it either, until I saw Alf's
response. Historically, "classical" C++ didn't allow
initializing an array in an initialization list (and it didn't
have the concept of default initialization---if the type didn't
have a non-trivial constructor, using () to initialize it didn't
do anything). And of course, once you know that something
doesn't work, there's no reason to study it further.
So where *do* people get this kind of information? As I said,
I tried googling for it, out of curiosity, and couldn't find
even one single mention, so it doesn't seem to be a pretty
common knowledge.
Well, I'm not too sure what sort of expression you'd use in
Google. More to the point, none of the examples in the standard
and elsewhere that I've seen use arrays. Like you, I'd always
assumed that it was illegal. In respones to Alf, however, I
tried to find where in the standard it said that you couldn't
specify an array in the initializer list, and couldn't---the
restriction just isn't there. The description of initializer
lists just refers to §8.5, which treats an empty () specially
(so that it can work with arrays---where as no other (...) is
legal with an array). So I tried it with three different
compilers (g++, Sun CC and VC++), and it worked with all of
them.
I guess you're never too old to learn.