-
operator overloading
Hi, I have three classes one is a game board, the other a human component and the other a computer component. i overload both the << >> operators in all three classes
function prototypes are:
/**Board Class***/
friend istream& operator>> (istream &, Board & );
/***Human Class*****/
friend istream& operator>> (istream &, Human &);
/****Computer Class****/
friend istream& operator>>(istream &, Computer &);
The Human class and the Computer class both have pointers to the Board class when i compile i get this error message
no match for 'operator>>' in "in>>Human->Human::Human_Player;
code for Human class is as follows
Human_Player is the pointer to the Board class
Code:
istream& operator>> (istream &in, Human &Human)
{
in>>Human.Human_Player;
return in;
}
-
You need to dereference a pointer to call a function that takes an object or reference. So since the operator>> of the Board class takes a Board reference, and you have a Board pointer, you need to dereference the pointer with *.
-
Thanks a lot I couldn't figure out how to derefrence the pointer I was using ->, and Human.(*Human_Player);