C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-12-2006, 05:16 AM   #1
Registered User
 
Join Date: Apr 2006
Posts: 11
A Tic Tac Toe game

What the hell?

Code:
/*-------Tic Tac Toe--------

             by Rusty_chainsaw */
             
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

class x {
      public:
             int typeX;
             bool winnerX = false;
      private:
              int numX = 5;
}

class o {
      public:
             int typeO;
             bool winnerO = false;
      private:
              int numO = 4;
}

class Moves {
      public:
             int turnX = true;
             int turnO = false;
}

int main()
{
    cout<<"\n[ ] [ ] [ ]\n[ ] [ ] [ ]\n[ ] [ ] [ ]\nIt's X's turn. Where would you like to place a 'X'? ";
}
It gives me a load of errors when I try and compile.

Code:
Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp" -o "C:\Documents and Settings\Gylfi\Desktop\TicTacToe.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:14: error: ISO C++ forbids initialization of member `winnerX'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:14: error: making `winnerX' static
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:14: error: ISO C++ forbids in-class initialization of non-const static member `winnerX'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:16: error: ISO C++ forbids initialization of member `numX'

C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:16: error: making `numX' static
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:16: error: ISO C++ forbids in-class initialization of non-const static member `numX'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:22: error: ISO C++ forbids initialization of member `winnerO'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:22: error: making `winnerO' static
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:22: error: ISO C++ forbids in-class initialization of non-const static member `winnerO'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:24: error: ISO C++ forbids initialization of member `numO'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:24: error: making `numO' static
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:24: error: ISO C++ forbids in-class initialization of non-const static member `numO'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:29: error: ISO C++ forbids initialization of member `turnX'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:29: error: making `turnX' static
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:29: error: ISO C++ forbids in-class initialization of non-const static member `turnX'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:30: error: ISO C++ forbids initialization of member `turnO'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:30: error: making `turnO' static
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:30: error: ISO C++ forbids in-class initialization of non-const static member `turnO'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:34: error: new types may not be defined in a return type
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:34: error: two or more data types in declaration of `main'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:34: error: two or more data types in declaration of `main'
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:34: error: extraneous `int' ignored
C:\Documents and Settings\Gylfi\Desktop\TicTacToe.cpp:34: error: `main' must return `int'

Execution terminated
Rusty_chainsaw is offline   Reply With Quote
Old 04-12-2006, 06:16 AM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
1. A class declaration is a different thing from the definition of an instance of that class.
You've basically done the equivalent of
int = 42;

You have to create an instance of the class before you can initialise members of the class (say using a constructor).

2. All your class declarations need to end with a ;
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tic Tac Toe game nafix C Programming 6 11-10-2007 01:45 PM
tic tac toe crashes :( stien Game Programming 4 05-13-2007 06:25 PM
2D RPG Online Game Project. 30% Complete. To be released and marketed. drallstars Projects and Job Recruitment 2 10-28-2006 12:48 AM
tic tac toe AI roadblock >:-(|) dark_rocket Game Programming 5 06-12-2006 05:13 AM
not 3x3 tic tac toe game AI Unregistered Game Programming 9 08-29-2001 04:02 AM


All times are GMT -6. The time now is 07:51 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22