So I'm trying to write a program to simulate Conway's game of life. I thought it'd be cool to declare a class called Cell and use an array of objects instead of an array of ints or bools. My problem is that when I go to compile a function to which I pass a multi-dimensional array of Cell, the compiler yells at me for not giving it a set size. (The size of my board varies). My code...

void printBoard(Cell board[][], int rows, int cols)
{
    system("cls");
 
    for(int i=0; i<rows; i++)
    {
    ...
}

With a little tinkering and browsing of samples on the internet, I noticed that making it a single dimensional array of ambiguous size works just fine, but soon as its more than one dimension, it says I must declare bounds.

I suspect there may be a way to work around this with pointers, but haven't figured it out yet. Suggestions?

Recommended Answers

All 2 Replies

You have to specify at least first dimension otherwise its not going to work anyway.
The secong dimension can be left unspecified.
Try managing by specifying one dimension at least(its compulsory).

> You have to specify at least first dimension otherwise its not going to work anyway.
> The secong dimension can be left unspecified.
Wrong way round - it's only the left-most dimension which can be left empty, all the minor dimensions need to be specified.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.