Overriding a method from the parent class not working as expected

  abstraction, c++, inheritance, overriding

I’ve got the following class structure where AnotherPlayer is the child of SomePlayer. I have the method getInternalMove implemented in SomePlayer and overridden it in AnotherPlayer. It is called inside getMove.

But when I call AnotherPlayer::getMove it doesn’t call getInternalMove in AnotherPlayer. What am I missing?

According to this question, it should call `AnotherPla

Note: The class structure may not seem ideal but note that this is the simplified form of a much complex scenario.




class SomePlayer{


public:

    void getMove(int player) {
        cout << "Get SomePlayer Moven";
        getInternalMove(player);
    }

    void getInternalMove(int player) {

        cout << "getInternalMove for SomePlayern";

    }
};

class AnotherPlayer: public SomePlayer {
public:


    void getInternalMove(int player){
        cout << "getInternalMove for  AnotherPlayern";

    }

};


int main() {

    AnotherPlayer p;
    p.getMove(0);

    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT