Error message

I am getting error c2448 'TestWinner' : function-style initializer appears to be a function definition. The error is pointing to the bool function definition, but I am not sure why or how to correct the problem. Does anyone have any ideas as to how to correct this?


#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

const int rows = 3; //Define number of rows in array
const int col = 3; //Define number of columns in array
int row, column;
char table [rows][col];
bool isWinner = false;
char letter;

void showarray(char [][col], int);
int spacetaken (int, int);
bool TestWinner();

int _tmain(int argc, _TCHAR* argv[])
{
int row, column;

char table [rows][col] = {{'*', '*', '*'},
{'*', '*', '*'},
{'*', '*', '*'}};
showarray(table, rows);

for (int count = 1; count <= 9; count++)
{
if (count % 2 != 0)
{
cout << "Player X's turn.\n";
cout << "Enter a row and column to place an X.\n";
cout << "Row:";
cin >> row;
cout << "Column:";
cin >> column;
cout << "\n";

//Warn player if space is already taken
if (table [row - 1] [column - 1] == 'X' || table [row - 1] [column - 1] == 'O')
{
spacetaken (row, column);
table [row - 1] [column - 1] = 'X';
}
else
table [row - 1] [column - 1] = 'X';

showarray(table, rows);
TestWinner();

if (isWinner == true)
{
cout << "Player X has won!/n";
cout << "The game will now end";

system ("pause");
system ("end");
}

}
else
{

cout << "Player O's turn.\n";
cout << "Enter a row and column to place an O.\n";
cout << "Row:";
cin >> row;
cout << "Column:";
cin >> column;
cout << "\n";

// Warn player if space is already taken
if (table [row - 1] [column - 1] == 'X' || table [row - 1] [column - 1] == 'O')
{
spacetaken(row, column);
table [row - 1] [column - 1] = 'O';
}
else
table [row - 1] [column - 1] = 'O';

showarray(table, rows);

TestWinner();

if (isWinner == true)
{
cout << "Player O has won!/n";
cout << "The game will now end";

system ("pause");
system ("end");
}
}
}
return 0;
}

void showarray (char array[] [col], int rows)
{
cout << "\tColumns\n";
cout << "\t 1 2 3\n";

for (int x = 0; x < rows; x++)
{
cout << "Row " << (x+1) << ": ";

for (int y = 0; y < col; y++)
{
cout << setw(3) << array [x] [y];
}
cout << "\n";
}

}

int spacetaken (int row, int column)
{
cout << "Space already taken, please select another space.\n";
cout << "Row:";
cin >> row;
cout << "Column:";
cin >> column;
cout << "\n";
return row, column;
}

bool TestWinner (table, letter)
{

if (table(0,0) == letter && table(1,1) == letter && table(2,2) == letter) //diagonal top left to bottom right
{
isWinner = true;
}
if (table(0,2)== letter && table(1,1) == letter && table(0,2) == letter) //diagonal top right to bottom left
{
isWinner = true;
}
if (table(0,0) == letter && table(1,0) == letter && table(2,0) == letter) //straight down, left column
{
isWinner = true;
}
if (table(0,1) == letter && table(1,1) == letter && table(2,1) == letter) //straight down, middle column
{
isWinner = true;
}
if (table(0,2) == letter && table(1,2) == letter && table(2,2) == letter) //straight down, right column
{
isWinner = true;
}
if (table(0,0) == letter && table(0,1) == letter && table(0,2) == letter) //horizontal top row
{
isWinner = true;
}
if (table(1,0) == letter && table(1,1) == letter && table(1,2) == letter) //horizontal middle row
{
isWinner = true;
}
if (table(2,0) == letter && table(2,1) == letter && table(2,2) == letter) //horizontal bottom row
{
isWinner = true;
}
return isWinner;
}
Could that be because table and letter don't have types?
Also, why did you declare (and use) the function without parameters?
Giving it parameters is giving me the same error. I am fairly new at this, so please bare with me.
To be honest with you, this is the first bool test that I have written.
odd. when I change it to bool TestWinner (char table[][3], char letter).. (I just noticed that table and letter are globals. Then this function doesn't need parameters at all) that error goes away.
You have others though. table(0,0) makes no sense. You probably meant table[0][0].
I realized the missing brackets, and figured out the parameter problem late last night. Thank you for your help.
Topic archived. No new replies allowed.