operator overloading

This is a discussion on operator overloading within the C++ Programming forums, part of the General Programming Boards category; Hi, I have three classes one is a game board, the other a human component and the other a computer ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    25

    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;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    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 *.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    25
    Thanks a lot I couldn't figure out how to derefrence the pointer I was using ->, and Human.(*Human_Player);

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21