I am working on a chess program. I have a base class called Piece and then other classes like Pawn, Rook, etc... Problem is that I can't get them to do dynamic binding. Here's the code that needs to do the dynamic binding:
in the piece class it looks like:Code:vector<location> Board::possibleMoves(location loc) { Piece* temp = &board[loc.row][loc.col]; vector<location> listLocs; listLocs = temp->getMoves(board); return listLocs; }
Finally I want the pawn class to overload this particular function and it looks like:Code:virtual vector<location> getMoves(vector<vector<Piece> > board) { cout<<"pay attention: "<<endl; vector<location> temp; return temp; }
You can see my debug code. It's still in there. When the function is called, it prints "pay attention" instead of "we made it". Any thoughts on what needs to be changed to make this perform dynamic binding?Code:vector<location> getMoves(vector<vector<Piece> > board) { cout<<"We made it"<<endl; vector<location> temp; //A bunch of stuff to figure out possible moves for a pawn return temp; }




Reply With Quote