Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

The Orange Peanut

2D array initialization

This topic is 5565 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

Advertisement
Guest Anonymous Poster
The Board is local to the constructor. Are you sending it as a parameter to DrawBoard()? What does the parameter list to DrawBoard() look like?

Share this post


Link to post
Share on other sites
Here is what my class looks like so far:


class TTTBoard
{
public:
//constructors and deconstructors

TTTBoard();
~TTTBoard();

//accessor methods

void ChangeSlot(int x, int y, int value);

//methods

void DrawBoard();


private:
int Board[3][3];

};

//constructor and destructor

TTTBoard::TTTBoard() //default constructor

{
int Board[3][3] = {
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
};
}
TTTBoard::~TTTBoard(){} //destructor


void TTTBoard::DrawBoard()
{
switch(Board[0][0])
{
case 0: cout<<"1";
break;
case 1: cout<<"X";
break;
case 2: cout<<"O";
break;
}
cout<<Board[0][0]; //used for testing

}



What should the parameters to DrawBoard() be? I thought that since the array was in the class, DrawBoard() didnt have to have it as a parameter? Im really confused... what should be the parameters and how do I use them in the function itself? I mean, suppose the function takes an array as a parameter. Would it be SomeFunction(AnArrayOfIntegers) or SomeFunction(AnArrayOfIntegers[5])?

Thanks in advance.

Share this post


Link to post
Share on other sites
remove int in the constructor. But this is not enough.
Change your constructor as below.

TTTBoard::TTTBoard() //default constructor

{
int tempBoard[3][3] = {
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
};

memcpy(&Board[0][0],&tempBoard[0][0],sizeof(tempBoard));
}

Also if you dont want anything that zeroing just use
memset. But do not redefine Board in constructor.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!