"Allan A." <AA@alphaville.com> wrote in message
news:dt*********@news4.newsguy.com...
: Hi all. Is there any way to initialize an entire array in the
constructor.
No, unfortunately, not in the current version of the C++ standard.
[ it is being proposed to allow this in the next revision of
the standard, but this is still years away. See for example
http://www.open-std.org/jtc1/sc22/wg...2005/n1919.pdf ]
: The code below does not work. Thanks.
:
: class x {
: public:
: int array[2][2];
: x();
:
: };
:
: x::x() {
: array = {{1,2},{3,4}};
: }
The actual (proposed) syntax for an initialization would
look like:
x::x()
: array( {{1,2},{3,4}} )
{ }
The example your provided uses assignment, not initialization,
to set the contents of the array. It could become legal as
well if(/once) the above proposal is integrated in the standard.
Equivalent code can (and has) be written today as individual
assignments to each element of the array.
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <>
http://www.brainbench.com