Discussion:
[Dev-C++] Invalid initializer for an array
Richard P. Evans
2000-10-10 03:07:54 UTC
Permalink
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
RoGeR
2000-10-10 06:39:36 UTC
Permalink
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 <***@mail.cvn.net>
To: <dev-cpp-***@lists.sourceforge.net>
Sent: Tuesday, October 10, 2000 06:07 AM
Subject: [Dev-C++] Invalid initializer for an array
Post by Richard P. Evans
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
http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
RoGeR
2000-10-10 11:54:11 UTC
Permalink
to initialize an array you do this :

int distribution [5] = { 1,2,3,4,5 }

----- Original Message -----
From: "RoGeR" <***@spidernet.net>
To: <dev-cpp-***@lists.sourceforge.net>
Sent: Tuesday, October 10, 2000 09:39 AM
Subject: Re: [Dev-C++] Invalid initializer for an array
Post by RoGeR
Probably the compiler's fault. Why don't you try creating a function that
handles that ?
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
fill_array ( distribution, 5, 0 );
Byezzz
----- Original Message -----
Sent: Tuesday, October 10, 2000 06:07 AM
Subject: [Dev-C++] Invalid initializer for an array
Post by Richard P. Evans
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
http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
_______________________________________________
Dev-cpp-users mailing list
http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
Ioannis Vranos
2000-10-10 11:57:01 UTC
Permalink
-----Original Message-----
Richard P. Evans
Sent: Tuesday, October 10, 2000 5:08 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);
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
Dee Zsombor
2000-10-10 12:07:26 UTC
Permalink
Post by Richard P. Evans
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
Matthew Hickson
2000-10-10 21:21:43 UTC
Permalink
Post by Dee Zsombor
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
Matthew Hickson
2000-10-10 21:24:27 UTC
Permalink
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
René Triebel
2000-10-09 22:37:05 UTC
Permalink
It works fine if you use {} instead of ()
Try this:

int distribution[5] = {0};

You´ll get no error message.

RT
-----Original Message-----
Behalf Of Richard
P. Evans
Sent: Tuesday, October 10, 2000 5:08 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
http://lists.sourceforge.net/mailman/listinfo/dev-cpp-users
Loading...