No matching function for call...

'This line is getting the error no matching function for call to TicTacToe::setField(int&, player*&)'

1
2
// TicTacToe.h
void setField( int aIndex, const Player& aPlayer );


1
2
3
4
5
// TicTacToe.cpp
void TicTacToe::setField( int aIndex, const Player& aPlayer )
{
    //....
}


1
2
3
4
5
6
7
8
9
// TicTacToeConsoleView.h
class TicTacToeConsoleView : public TicTacToeView
{
private:
	Player *fPlayers[2];
//.....
//.....
//.....
}



1
2
3
4
//TicTacToeConsoleView.cpp

// this line is in a function and get the error mentioned
fModel->setField(guess, fPlayers[i]);
setField accepts two parameters. An int, and a Player. You are trying to feed it an int, and a pointer to a Player.

fPlayers is an array of pointers to Player; it is not an array of Player objects.
Last edited on
Is there a way around it i sort of have to leave fPlayers as an array of pointers...
When you need to deal with what a pointer is pointing to, you can use the dereference operator * .

In this case, try

fModel->setField(guess, *(fPlayers[i]));

This will of course rely on the pointer pointing to an actual Player object, which you will have had to arrange at some point.
Last edited on
It worked but now its got an error somewhere else in the TicTacToeConsoleView.cpp on this line...

1
2
3
4
5
6
fPlayers[0] = new Player(tmp1Name, 'X');
fPlayers[1] = new Player(tmp2Name, 'O');

// ...

if (fPlayers[i].getName() == "Computer")


Only on the first and third lines though for some strange reason?! 2nd player declaration seems to not error...

What is the error?

if (fPlayers[i].getName() == "Computer")
This line makes no sense; fPlayers[i] is a pointer, and pointers do not have member functions. I suspect you mean to call the member function of what that pointer actually points to. Try

if (fPlayers[i]->getName() == "Computer")
Last edited on
Says 'fPlayers was not declared in this scope'... and yeh fixed that still occurs though
At the point in the program you're trying to use fPlayers, it does not exist. If this is inside a function, then you need a way to pass fPlayers to that function, or to make fPlayers some kind of hideous global variable, or provide some way that the function can fetch fPlayers.


http://www.cplusplus.com/doc/tutorial/variables/ - in particular, the section headed Scope of variables
Last edited on
hmm nevermind works great! i accidentally removed 'f'... thanks a tonne!!!
Topic archived. No new replies allowed.