Arrays with classes compile error

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
#include <iostream>
#include <string>
#include <iomanip>
class Tic
{
      private: 
               int turn;
               char position[3][3];
               int status;
      public:
             Tic();
             void drawboard();
             void checkstatus();
             void changeturn(int);
             
};
using namespace std;
int main()
{
Tic player;
player.drawboard();


system("PAUSE");
return 0;
  
}
Tic::Tic(): turn(0),status(0)
{
            
            position[0,0]='x';
            position[0,1]='x';
            position[0,2]='x';
            position[1,0]='x';
            position[1,1]='x';
            position[1,2]='x';
            position[2,0]='x';
            position[2,1]='x';
            position[2,2]='x';
            
}


                              
void Tic::drawboard()
{
     cout<<"           |           |           \n"
         <<"      "<<position[0,0]<<"      |      "<<position[0,1]<<"      |      "<<position[0,2]<<endl
         <<"           |           |           \n"
         <<" ---------- ----------- -----------\n" 
         <<"           |           |           \n"
         <<"      "<<position[1,0]<<"      |      "<<position[1,1]<<"      |      "<<position[1,2]<<endl
         <<"           |           |           \n"
         <<" ---------- ----------- -----------\n"
         <<"           |           |           \n"
         <<"      "<<position[2,0]<<"      |      "<<position[2,1]<<"      |      "<<position[2,2]<<endl 
         <<"           |           |           \n";    
         
}



When compiling I get the following error:

t.cpp: In constructor 'Tic::Tic()':
Line 32: error: incompatible types in assignment of 'char' to 'char [3]'
compilation terminated due to -Wfatal-errors.

What's the proper way to use arrays in a class?
Thanks.

Note: I'm setting the default values as 'x' to test out my tic tac toe board layout.
Last edited on
That's not how you access 2D+ arrays. You need to do this:

array[value1][value2];
ohhh whoops, i was thinking of maple :P thanks for your help
Topic archived. No new replies allowed.