473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Having difficulty with constructor

blackstormdragon
Okay I have to make this TicTacToe program. Everything works except my constructor(which must initialize my empty board to all zeros) This is where I run into problems. For some reason my constructor won't do anything. Everything looks right, so I don't know what to do. Here's a snipit of my code.
Expand|Select|Wrap|Line Numbers
  1. class TicTacToe
  2. {
  3. public:
  4.     TicTacToe();
  5.     int checkWinner();
  6.     void printBoard();
  7.     void playGame();
  8. private:
  9.     char board[3][3];
  10.     bool winner;
  11.     int row, column, turn;  
  12. };
  13.  
  14. int main()
  15. {
  16.     TicTacToe game;
  17.  
  18.     game.playGame(); 
  19.  
  20. }
  21. TicTacToe::TicTacToe()
  22. {
  23.  
  24.      for(int index = 0; index < 3; index++)
  25.      {
  26.          for(int index2 = 0; index2 < 3; index2++)
  27.          {
  28.              board[index][index2] = 0;
  29.          }
  30.      }
Thanks
Sep 5 '07 #1
2 1061
ilikepython
844 Expert 512MB
Okay I have to make this TicTacToe program. Everything works except my constructor(which must initialize my empty board to all zeros) This is where I run into problems. For some reason my constructor won't do anything. Everything looks right, so I don't know what to do. Here's a snipit of my code.
Expand|Select|Wrap|Line Numbers
  1. class TicTacToe
  2. {
  3. public:
  4.     TicTacToe();
  5.     int checkWinner();
  6.     void printBoard();
  7.     void playGame();
  8. private:
  9.     char board[3][3];
  10.     bool winner;
  11.     int row, column, turn;  
  12. };
  13.  
  14. int main()
  15. {
  16.     TicTacToe game;
  17.  
  18.     game.playGame(); 
  19.  
  20. }
  21. TicTacToe::TicTacToe()
  22. {
  23.  
  24.      for(int index = 0; index < 3; index++)
  25.      {
  26.          for(int index2 = 0; index2 < 3; index2++)
  27.          {
  28.              board[index][index2] = 0;
  29.          }
  30.      }
Thanks
Since yout board variable is a char [][] try initializing it with '0':
Expand|Select|Wrap|Line Numbers
  1. board[index][index2] = '0';
  2.  
Other than that, it looks fine.
Sep 6 '07 #2
Since yout board variable is a char [][] try initializing it with '0':
Expand|Select|Wrap|Line Numbers
  1. board[index][index2] = '0';
  2.  
Other than that, it looks fine.
Yeah that was it. Thanks. I can't belive I missed it.
Sep 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stephen Horne | last post by:
Just recently I decided I want to make use of my ISP freebie webspace. In order to make that easier, I'd like to be able to automatically synchronise an FTP file/folder heirarchy with one on my...
1
by: George | last post by:
Hi, I am trying to write a query in Oracle which I have not done before, and are having some difficulty getting my result. Please check my query and my results. select max(note.datetime),...
14
by: Gregory L. Hansen | last post by:
I can't seem to make a queue of objects, using the STL queue. I'm trying to make a little event manager, and I just want someplace to store events. The method definitions for EventManager have...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
1
by: Jay Douglas | last post by:
I need help getting the collections to show up in the property window of a user control. I want to be able to edit the collection items just like any other asp.net control that has collection...
4
by: TS | last post by:
I am trying to add an event handler for a static variable of a class and i can't figure out how to do so since the class is never instantiated. The wmp variable gets instantiated when my code...
3
by: infinity | last post by:
Hi all, Is constructor a special member function? But I don't think it is either a member function or even a special member function although it has the syntax of a function. I think it confused...
12
by: Edward Diener | last post by:
Given value class X { public: // Not allowed: X():i(100000),s(10000) { } // Allowed void InitializeDefaults() { i = 100000; s = 10000; } private: int i;
1
by: patilanjana | last post by:
Hi, I am getting above mentioned errors. Checked msdn, read the comments but I fail to implement it. Please help. Error is regarding using the new and delete operators. Although I do write...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.