Pointer to a function used in arithmetic

closed account (1v5E3TCk)
I am still working on my draughts game and i code a little but when try to compile the first part of the game i get that error:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
In function 'int main()':
25	30	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Warning] pointer to a function used in arithmetic [-Wpointer-arith]
25	33	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Warning] pointer to a function used in arithmetic [-Wpointer-arith]
25	35	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Error] assignment of read-only location '*(tahta + (((sizetype)i) + ((sizetype)j)))'
25	35	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Error] cannot convert 'const char [4]' to 'int(std::string (*)[8], std::string) {aka int(std::basic_string<char> (*)[8], std::basic_string<char>)}' in assignment
34	15	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Warning] pointer to a function used in arithmetic [-Wpointer-arith]
34	18	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Warning] pointer to a function used in arithmetic [-Wpointer-arith]
34	20	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Error] assignment of read-only location '*(tahta + (((sizetype)i) + ((sizetype)j)))'
34	20	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Error] cannot convert 'const char [4]' to 'int(std::string (*)[8], std::string) {aka int(std::basic_string<char> (*)[8], std::basic_string<char>)}' in assignment
46	32	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Warning] pointer to a function used in arithmetic [-Wpointer-arith]
46	37	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Warning] pointer to a function used in arithmetic [-Wpointer-arith]
46	39	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Error] assignment of read-only location '*(tahta + (((sizetype)i) + ((sizetype)j)))'
46	39	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Error] cannot convert 'const char [4]' to 'int(std::string (*)[8], std::string) {aka int(std::basic_string<char> (*)[8], std::basic_string<char>)}' in assignment
55	17	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Warning] pointer to a function used in arithmetic [-Wpointer-arith]
55	22	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Warning] pointer to a function used in arithmetic [-Wpointer-arith]
55	24	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Error] assignment of read-only location '*(tahta + (((sizetype)i) + ((sizetype)j)))'
55	24	C:\Users\-exper-\Desktop\exercises\dama.cpp	[Error] cannot convert 'const char [4]' to 'int(std::string (*)[8], std::string) {aka int(std::basic_string<char> (*)[8], std::basic_string<char>)}' in assignment



And that is my code:

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  #include <iostream>

using namespace std;

int tahta( string dama[ ][ 8 ], string oyuncu);
//int kontrol( string );

//int x;
//int y;


int main()
{
	string dama[ 8 ][ 8 ];
	
	string oyuncu1;
	string oyuncu2;
	
	for( int i=0; i<8; ++i)
	{
		if( i % 2 == 0 )
			{
				for( int j=1; j<8; j+=2)
                     {
                     	tahta[ i ][ j ]=":::";
                     }

			}
			
		if( i % 2 == 1 )
			{
				for( int j=0; j<8; j+=2)
					 {
					 	tahta[ i ][ j ]=":::";
					 }
			}
				
	}	
	
		for( int i=0; i<8; ++i)
	{
		if( i % 2 == 0 )
			{
				for( int j=0; j<8; j+=2)
                     {
                     	tahta[ i ][ j ]="   ";
                     }

			}
			
		if( i % 2 == 1 )
			{
				for( int j=1; j<8; j+=2)
					 {
					 	tahta[ i ][ j ]="   ";
					 }
			}
				
	}
	
	tahta( dama , oyuncu1 );
	//kontrol( tas , oyuncu1 );
	//hamle;
	
	//tahta( dama , oyuncu2 );
	//kontrol( tas , oyuncu2 );
	//hamle;
	
}

int tahta( string dama[ ][ 8 ] , string oyuncu )
{
	for( int i=1; i<8; ++i)
	{
			cout<<"|";	
		for( int j=1; j<8; ++j)
		{
			cout<< dama[ i ][ j ]<< "|";
		}
		cout<<endl;
	}
	cin.get();
}
Replace every tahta[ i ][ j ] with dama[ i ][ j ]

(and while you're at it, give tahta a return statement, you said it returns an int, but you never returned any)
closed account (1v5E3TCk)
Thanks man i have corrected everything and my new code is that:

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <iostream>

using namespace std;

void tahta( string dama[ ][ 8 ], string oyuncu);
int kontrol( string dama[ ][ 8 ], int oyuncu );
void hamle( string dama[ ][ 8 ]);


int x;
int y;


int main()
{
	///////////////////TAHTA////////////////////////
	
	string dama[ 8 ][ 8 ];
	
	string oyuncu1;
	string oyuncu2;
	
	for( int i=0; i<8; ++i)
	{
		if( i % 2 == 0 )
			{
				for( int j=1; j<8; j+=2)
                     {
                     	dama[ i ][ j ]=":::";
                     }
            	
				for( int j=0; j<8; j+=2)
                     {
                     	dama[ i ][ j ]="   ";
                     }
                
			}
			
		if( i % 2 == 1 )
			{
				for( int j=0; j<8; j+=2)
					 {
					 	dama[ i ][ j ]=":::";
					 }
					 
				for( int j=1; j<8; j+=2)
					 {
					 	dama[ i ][ j ]="   ";
					 }
					 
					 
			}
				
	}	
	
	///////////////////BAŞLANGIÇ////////////////////
	
	for(int j=0; j<8; j+=2)
		{
			dama[ 1 ][ j ] = ":K:";
			dama[ 2 ][ j ] = " K ";
		}
	for(int j=1; j<8; j+=2)
		{
			dama[ 1 ][ j ] = " K ";
			dama[ 2 ][ j ] = ":K:";
		}
		
	for(int j=0; j<8; j+=2)
		{
			dama[ 5 ][ j ] = ":S:";
			dama[ 6 ][ j ] = " S ";
		}
	for(int j=1; j<8; j+=2)
		{
			dama[ 5 ][ j ] = " S ";
			dama[ 6 ][ j ] = ":S:";
		}

    ////////////////HAMLELER////////////////////////
	
	while(1)
	{
	  tahta( dama , oyuncu1 );
	  if( kontrol( dama, 1 ) == 1)
	  	{
	  		break;
	  	}
	
	  cout<< "\n\nHatali giris yaptiniz.\n";
	  	
	}
	
	hamle( dama );
	
	//tahta( dama , oyuncu2 );
	//kontrol( ikinci );
	//hamle;
	
}


void tahta( string dama[ ][ 8 ] , string oyuncu )
{   
    int a=0;
    
	cout<<"   0   1   2   3   4   5   6   7   \n";
    
	for( int i=0; i<8; ++i)
	{   
			cout<< a;
			cout<<"|";	
	
	
		for( int j=0; j<8; ++j)
		{
			cout<< dama[ i ][ j ]<< "|";
		}
		cout<<endl;
		++a;
	}
    
	cout<< "Oynamak istediginiz tasin yatay numarasini girin.";
	cin>> x;
	
	cout<< "Oynamak istediginiz tasin dikey numarasini girin.";
	cin>> y;	
		
}

int kontrol( string dama[ ][ 8 ], int oyuncu)
{
	if ( oyuncu == 1 )
	{
		if ( dama[ y ][ x ] == ":S:" || dama[ y ][ x ] == " S " )
		{
			return 1;
		}
	
		else 
		{   return 0; }
	
	}

	if ( oyuncu == 2 )
	{
		if ( dama[ y ][ x ] == ":K:" || dama[ y ][ x ] == " K " )
		{
			return 1;
		}
	
		else 
		{   return 0; }
	
	}	
	
}

void hamle( string dama[ ][ 8 ])
{
	int a;
	int b;
	
	cout<< "Oynamak istediginiz yerin yatay numarasini girin.";
	cin>> a;
	
	cout<< "Oynamak istediginiz yerin dikey numarasini girin.";
	cin>> b;
	
	    if ( ( (a == x-1 || a == x+1) && b == y ) || ( b == y-1 && a == x ))
	    	{
	    		if ( dama[ b ][ a ] == "   ")
	    		{
	    			 dama[ b ][ a ] = " S ";
	    			 dama[ y ][ x ] = "   ";
	    		}
	    		
	    		if ( dama[ b ][ a ] == ":::")
	    		{
	    			 dama[ b ][ a ] = ":S:";
	    			 dama[ y ][ x ] = ":::";
	    		
				}
	    		
	    	}
}
Topic archived. No new replies allowed.