0

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?

3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Salem
0

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).

0

> 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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.