Cannot allocate array

S

saneman

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?
 
I

Ian Collins

saneman said:
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;
 
J

Juha Nieminen

Ian said:
saneman said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top