From: Richard P. E. <ev...@ma...> - 2000-10-10 03:00:58
Why do I get an "invalid initializer" message for the following line in my
program?
int distribution[5] = (0);
It seems the only thing that works to initialize an array is a "for"
statement. Does anyone have an answer? The above line is by the book and
should work. Or is this a software bug? Some how I doubt that.
Richard Evans
Probably the compiler's fault. Why don't you try creating a function that
handles that ?
E.g. :
template <class ARRAY_TYPE>
void fill_array ( ARRAY_TYPE [] &arrary, int number_of_items, ARRAY_TYPE
fill_value = 0 )
{ for ( int i=0; i < number_of_items; i++ )
array[i] = fill_value; } }
I know you said you didn't want the for thing... but making it a function
becomes really easy to use :
fill_array ( distribution, 5, 0 );
Byezzz
----- Original Message -----
From: Richard P. Evans <ev...@ma...>
To: <dev...@li...>
Sent: Tuesday, October 10, 2000 06:07 AM
Subject: [Dev-C++] Invalid initializer for an array
> Why do I get an "invalid initializer" message for the following line in my
> program?
>
> int distribution[5] = (0);
>
> It seems the only thing that works to initialize an array is a "for"
> statement. Does anyone have an answer? The above line is by the book and
> should work. Or is this a software bug? Some how I doubt that.
>
> Richard Evans
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
>
to initialize an array you do this :
int distribution [5] = { 1,2,3,4,5 }
----- Original Message -----
From: "RoGeR" <le...@sp...>
To: <dev...@li...>
Sent: Tuesday, October 10, 2000 09:39 AM
Subject: Re: [Dev-C++] Invalid initializer for an array
> Probably the compiler's fault. Why don't you try creating a function that
> handles that ?
> E.g. :
>
> template <class ARRAY_TYPE>
> void fill_array ( ARRAY_TYPE [] &arrary, int number_of_items, ARRAY_TYPE
> fill_value = 0 )
> { for ( int i=0; i < number_of_items; i++ )
> array[i] = fill_value; } }
>
> I know you said you didn't want the for thing... but making it a function
> becomes really easy to use :
>
> fill_array ( distribution, 5, 0 );
>
> Byezzz
>
> ----- Original Message -----
> From: Richard P. Evans <ev...@ma...>
> To: <dev...@li...>
> Sent: Tuesday, October 10, 2000 06:07 AM
> Subject: [Dev-C++] Invalid initializer for an array
>
>
> > Why do I get an "invalid initializer" message for the following line in
my
> > program?
> >
> > int distribution[5] = (0);
> >
> > It seems the only thing that works to initialize an array is a "for"
> > statement. Does anyone have an answer? The above line is by the book
and
> > should work. Or is this a software bug? Some how I doubt that.
> >
> > Richard Evans
> >
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
> >
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
>
From: Ioannis V. <no...@ya...> - 2000-10-10 10:56:11
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...]On Behalf Of
> Richard P. Evans
> Sent: Tuesday, October 10, 2000 5:08 AM
> To: dev...@li...
> Subject: [Dev-C++] Invalid initializer for an array
>
>
> Why do I get an "invalid initializer" message for the following
> line in my
> program?
>
> int distribution[5] = (0);
>
int distribution[5]={0,0,0,0,0};
> It seems the only thing that works to initialize an array is a "for"
> statement. Does anyone have an answer? The above line is by the
> book and
> should work. Or is this a software bug? Some how I doubt that.
I am new at C++, but i think that your initialisation is somehow wrong.
Ioannis
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
On Tue, 10 Oct 2000, Ioannis Vranos wrote:
> >
> > Why do I get an "invalid initializer" message for the following
> > line in my
> > program?
> >
> > int distribution[5] = (0);
> >
> > It seems the only thing that works to initialize an array is a "for"
> > statement. Does anyone have an answer? The above line is by the
> > book and
> > should work. Or is this a software bug? Some how I doubt that.
Try this int distrubution[]={0,0,0,0,0}
It means an array of ints ,with proper size (5), initialized with all
elements to 0.
zsombi
From: Matthew H. <mhi...@ko...> - 2000-10-10 21:20:54
> Try this int distrubution[]={0,0,0,0,0}
>
> It means an array of ints ,with proper size (5), initialized with all
> elements to 0.
You could also replace the {0,0,0,0,0} with {0} (if I recall properly, this
works with all ANSI C/C++ compilers).
-----
Matthew Hickson
From: Matthew H. <mhi...@ko...> - 2000-10-10 21:23:37
Hello everybody,
Just a quick question regarding Dev-C++ (I'm using v3.9).
Has anybody encountered a good class builder utility? Ideally something
along the lines of MSVC++ v5. Nothing super special, just something to
generate standard C++ classes (most preferably with a Windows interface).
Thanks,
-----
Matthew Hickson