Array Problem - Need Help

Started by
1 comment, last by GameDev.net 18 years ago
Im new a programming. Currently, im in the process of learning C++ and ive been learning about arrays. I have started to create a TicTacToe game and am going to use an array to create the board. Right now im creating the instructions which includes a board with numbers for the different slots. I want to use an array to display that instruction "board" also, but im having difficulties. Here is the code that is within a Class: private: char player_Choice; int instruct_Board[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; char ttt_Board[3][3]; public: void Instructions() //Tells how the GameBoard is set up @ How to use it { cout<< "Here is how the game works!!!\n\n" << "There are two players. One player is 'X' the other player is 'O'\n\n"; for(int x = 0; x < 3; ++x) { for(int y = 0; y < 3; ++y) cout<< instruct_Board[x][y]; cout<<endl; } As you can see i have a multidimensional array called instruct_board. The problem is, it wont let me compile that array the way it is. It tried setting up this same board in another program but i set it up in the "main" function. When set up in the "main" function, it worked just fine. It compiled and displayed the instruction board. My question is: Because I have the array set up in a Class, do the rules somehow change? Is there something else messing with it? Please any help would be appriciative.
Cheers,Ken(Koolchamp)_____________________________"Choose a job you love, and you will never have to work a day in your life." - Confucius"If you don't have a game industry job and you want to go to E3, do what everyone else does. Launch a game review website and call yourself press." - Mike McShaffry(This is true for me) “…..I'm a geek and jocks are my natural enemy.” – Li C. Kuo
Advertisement
Hey bud,

You can't do:

class myClass{  int myArray[3] = {1,2,3};};


and the like,

You will have to allocate it dynamically and clean it up at the end.

Dave
My suggestion is that you have the constructor of the class allocate the actual data of the array

This topic is closed to new replies.

Advertisement