"xyz does not name a type" error
Jan 5, 2014 at 11:35pm UTC
Hi,
As shown below, I am trying to make a tictactoe game. It is not complete yet.
I am trying to use the code from this tutorial:
http://www.cplusplus.com/forum/beginner/52609/
You will notice that the tutorial has three separate files: main.cpp, tictactoe.h, and tictactoe.cpp. As I was not sure how to combine these three files in my project, I tried to put them in one file as shown in my code below.
Based on my C programming experience this arrangement should work, but not sure what is wrong.
I am getting the following errors:
error: 'class' does not name a type - on the line where I define the 'tictactoe class'
error: 'tictactoe' does not name a type - on the line where I define the 'tictactoe' constructor function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
Class Tictactoe
{
private :
int pos[9]; // board position
int player; // current player
int totalTurns; // how many turns so far?
int numberPlayers; // 1 to 20
bool playerType[20]; // player #, 0 = comp, 1 = human
public :
TicTacToe(); // constructor
void printTurn();
bool playerHuman();
void humanMove();
void computerMove();
void drawBoard();
bool Winner();
bool fullBoard();
void nextTurn();
};
TicTacToe::TicTacToe()
{
srand (time(0));
player = 1; // who starts first?
totalTurns = 0;
// new player setup
numberPlayers = 2;
playerType[1] = 1; // playerType[player] is human (1)
playerType[2] = 0; // playerType[player] is computer (0)
for (int i = 0; i < 9; i++)
pos[i] = 0;
};
int main()
{
int pos[9];
//fills the position array with zeros
for (int i=0; i<9; i++ )
{
pos[i] =0;
}
// output the contents of the position array
cout << endl
<<" " << pos[0] << " " << (char )179 <<" " << pos[1] << " " << (char )179 << " " << pos[2]
<< "\n----" << (char )197 << "---" << "--" << (char )197 << "---" << "\n"
<< " " << pos[3] << " " << (char )179 <<" " << pos[4] << " " << (char )179 << " " << pos[5]
<< "\n----" << (char )197 << "---" << "--" << (char )197 << "---" << "\n"
<<" " << pos[6] << " " << (char )179 <<" " << pos[7] << " " << (char )179 << " " << pos[8]<<endl;
return 0;
}
Last edited on Jan 5, 2014 at 11:36pm UTC
Jan 5, 2014 at 11:41pm UTC
C++ is case-sensitive.
This means that class and Class and CLASS and claSs are all different.
So line 7 should read:
class TicTacToe
Topic archived. No new replies allowed.