
www.Usenet.com
| <-- __Chronological__ --> | <-- __Thread__ --> |
For what it's worth, I found that I CAN use
const int var = 4;
instead of
#define var 4
in C++ but not in C
Apparently, 'const' is preferred with C++ users vs. '#define' due to type
checking
"jmh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>
> Mike Hodkin wrote:
> > Quick question:
> >
> > why can't I use a variable to initialize an array, even though I declare
the
> > array, e.g.
> >
> > int var = 4;
> > float myarray[var] = {1,2,3,4};
> >
> > the compiler gives an error: "variable sized object may not be
initialized"
> >
> > thanks
>
> Don't know the answer but would guess that it's because the
> array must be a fixed size and the value of var could be
> changed.
>
> If you want to specify the size of an array without actually
> using the number try:
>
> #define ARRAY_SIZE 4
>
> float mayarray[ARRAY_SIZE] = ...
>
> Also interested in hearing the technical/actual answer.
>
> jmh
>
| <-- __Chronological__ --> | <-- __Thread__ --> |