Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Cannot allocate array

Reply
Thread Tools

Cannot allocate array

 
 
saneman
Guest
Posts: n/a
 
      08-01-2008
I get the following error when I try to allocate the below code:

cannot allocate an array of constant size 0

int main() {
int dim = 3;
int b[dim][dim];

return 0;
}


What am I doing wrong?


 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      08-01-2008
saneman wrote:
> I get the following error when I try to allocate the below code:
>
> cannot allocate an array of constant size 0
>
> int main() {
> int dim = 3;
> int b[dim][dim];
>
> return 0;
> }
>
>
> What am I doing wrong?
>

Not using a C99 compiler.

To be legal c++, you should uee a const:

const size_t dim = 3;

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      08-02-2008
Ian Collins wrote:
> saneman wrote:
>> I get the following error when I try to allocate the below code:
>>
>> cannot allocate an array of constant size 0
>>
>> int main() {
>> int dim = 3;
>> int b[dim][dim];
>>
>> return 0;
>> }
>>
>>
>> What am I doing wrong?
>>

> Not using a C99 compiler.
>
> To be legal c++, you should uee a const:
>
> const size_t dim = 3;


const int dim = 3; would be fine too.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot allocate memory when using os.spawn for moving files Andreas Python 1 03-18-2009 09:35 PM
"error C2057: expected constant expression", "error C2466: cannot allocate an array of constant size 0". Why doesn't my simple program work??? hn.ft.pris@gmail.com C++ 13 01-22-2007 02:03 PM
Dinamically allocate array of array of structures valerio C Programming 3 09-01-2006 11:45 PM
popen cannot allocate memory rveloso C Programming 1 04-04-2006 05:33 AM
Re: FileChannel.map() gives 'cannot allocate memory' Roedy Green Java 3 08-14-2003 08:44 PM



Advertisments