A Tic Tac Toe game

This is a discussion on A Tic Tac Toe game within the C++ Programming forums, part of the General Programming Boards category; What the hell? Code: /*-------Tic Tac Toe-------- by Rusty_chainsaw */ #include <iostream> #include <fstream> #include <string> using namespace std; class ...

  1. #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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    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.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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