473,513 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot allocate array

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?
Aug 1 '08 #1
2 1682
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.
Aug 1 '08 #2
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.

Aug 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3166
by: overbored | last post by:
I can do this: int asdf; int* zxcv = asdf; but not this: int asdf; int** zxcv = asdf;
3
2666
by: Richard Cavell | last post by:
#include <gmp.h> mpz_t* p_mympz = new mpz_t; error: cannot convert '__mpz_struct*' to '__mpz_struct (*)' in initialization 1. What does that mean? 2. Given that mpz_t doesn't have a...
3
18742
by: Simon | last post by:
Hello everybody, I've got a problem. I'm trying to allocate an array inside a function with Parameter int n: main(){ int i; .... i = strlen(ch); array(i); ....
6
21629
by: Rene | last post by:
Could anyone tell me what is the reason I can't initialize the members of a struct like this: public struct SomeStruct { public int uno = 1; // Error public int dos = 2; // Error public...
12
8062
by: paul | last post by:
Hi everyone, I'm debugging an FFT routine and it has thrown up a perplexing error which I cannot trace. Cannot anyone help? I've included the relevant code below with comments: rlft3(data_in1,...
3
2670
by: valerio | last post by:
Hello all I would like to dinamically allocate an array of array of structures. To explain this: struct file{ char* fileName,int inode) myfiles; struct file{ char* fileName,int inode) mydirs; ...
13
27394
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
5
6034
by: Siegfried Heintze | last post by:
On line 5 of the program below I get the error message in the subject line. (1) How may I correct it? (2) How may I enhance my Arr class to work with a foreach statement? (3) In C++ I can pass...
3
6890
by: Samant.Trupti | last post by:
HI, I want to dynamically allocate array variable of type LPWSTR. Code looks like this... main() { LPWSTR *wstr; int count = Foo (wstr); for (int i = 0; i < count; i++) //print each...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.