Jump to content
  • Advertisement
Sign in to follow this  
Koolchamp

Array Problem - Need Help

This topic is 4591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
My suggestion is that you have the constructor of the class allocate the actual data of the array

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!