943,962 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 5211
  • C RSS
Mar 27th, 2007
0

Passing multi-dimensional array

Expand Post »
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...

  1. void printBoard(Cell board[][], int rows, int cols)
  2. {
  3. system("cls");
  4.  
  5. for(int i=0; i<rows; i++)
  6. {
  7. ...
  8. }

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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
delner is offline Offline
5 posts
since Mar 2007
Mar 27th, 2007
0

Re: Passing multi-dimensional array

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).
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Masood Ali is offline Offline
19 posts
since Mar 2007
Mar 27th, 2007
0

Re: Passing multi-dimensional array

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: C
Next Thread in C Forum Timeline: solve equadratric equation in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC