![]() |
| ||
| Using 2D Arrays inside Classes Hello, I am trying to declare a 2D array (3x3) inside of a class. I have it set up like this: GameBoard.cpp #include "GameBoard.h"Game.cpp (Driver) #include "GameBoard.h"GameBoard.h #ifndef GAME_H What I am trying to do right now is be able to display my array using the class. I tried some of those but they were illegal declarations. |
| ||
| Re: Using 2D Arrays inside Classes Um, board isn't a member of the GameBoard class. It's a global variable. |
| ||
| Re: Using 2D Arrays inside Classes Okay I figured out the default constructor. Now I need to create a function named "playerChoice" which changes the stored array value into whatever the player's space that is chosen and replaces it with an 'X' or 'O' and then calls a function to print out the current board status. |
| ||
| Re: Using 2D Arrays inside Classes Hey I think your one of your functions is incorrect are you sure its not like this? ostream&printBoard(ostream&); |
| ||
| Re: Using 2D Arrays inside Classes If you want to sharing your global variables, use 'static' on them.. Example: static int myArray[2][2]; |
| ||
| Re: Using 2D Arrays inside Classes Quote:
|
| All times are GMT -4. The time now is 11:24 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC