943,929 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 564
  • C++ RSS
Oct 24th, 2008
0

Compiler error

Expand Post »
This code is giving me the error "expected primary-expression before ']' token." After googling and looking around Daniweb I still cannot find what this means. Can anyone enlighten me?

C++ Syntax (Toggle Plain Text)
  1. int board[*width][*height];
  2. if(OpenBoard(boardName, width, height, board[][*height]))
  3. {
  4.  
  5. }
  6.  
  7. //...
  8. //function definition...
  9.  
  10. bool OpenBoard(std::string *boardFileName, int *width, int *height, int board[][100])
Similar Threads
Reputation Points: 104
Solved Threads: 27
Posting Whiz in Training
dmanw100 is offline Offline
239 posts
since Apr 2008
Oct 24th, 2008
0

Re: Compiler error

Arrays need to be declared with constants, not variables.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Oct 24th, 2008
0

Re: Compiler error

Well i dont think arrays can be initialised with variables.

i think vectors are the suitable task for the job.
Reputation Points: 673
Solved Threads: 125
Practically a Posting Shark
Sky Diploma is offline Offline
818 posts
since Mar 2008
Oct 24th, 2008
0

Re: Compiler error

You can't declare arrays using sizes available at run-time.

Given that your function definition has a constant, how about
C++ Syntax (Toggle Plain Text)
  1. int board[100][100];
  2. if(OpenBoard(boardName, width, height, board))
  3. {
  4.  
  5. }
  6.  
  7. //...
  8. //function definition...
  9.  
  10. bool OpenBoard(std::string *boardFileName, int *width, int *height, int board[][100])

But since this is C++, how about
std::vector< std::vector<int> > board;
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 24th, 2008
1

Re: Compiler error

Thanks guys I really appreciate it! I've been puzzled for a few hours haha
Reputation Points: 104
Solved Threads: 27
Posting Whiz in Training
dmanw100 is offline Offline
239 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Problems passing multidimensional arrays
Next Thread in C++ Forum Timeline: Character Processing and use of Functions





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


Follow us on Twitter


© 2011 DaniWeb® LLC