I am trying to reduce the length of a long function by splitting it up into smaller components, but I encounter the error 'undefined reference to Pawn::generateCaptureMoves(Pawn, ...) const'
, Pawn::generateForwardMoves(Pawn, ...) const'
, Pawn::generateEnPassantMoves(Pawn, ...) const'
when I try to compile my file.
Pawn.h
#pragma once
#include "Piece.h"
#include <vector>
// Represents a pawn
struct Pawn : public Piece {
Pawn(Team, int, int); // Constructor
moveTypes calcPossibleMoves(Piece*[8][8]) const override;
void generateCaptureMoves(Pawn p, moveTypes moves, Piece*[8][8], int) const;
void generateForwardMoves(Pawn p, moveTypes moves, Piece*[8][8], int) const;
void generateEnPassantMoves(Pawn p, moveTypes moves, Piece*[8][8]) const;
};
Pawn.cpp
#include "Pawn.h"
#include <vector>
Pawn::Pawn(Team team, int xPos, int yPos): Piece(team, xPos, yPos, PieceType::PAWN, "p") {}
moveTypes Pawn::calcPossibleMoves(Piece* board[8][8]) const {
moveTypes moves;
int dir = (getTeam() == Team::WHITE)? -1: 1;
int xPos = getX(), yPos = getY();
generateCaptureMoves(*this, moves, board, dir);
generateForwardMoves(*this, moves, board, dir);
generateEnPassantMoves(*this, moves, board);
return moves;
};
void generateCaptureMoves(Pawn p, moveTypes moves, Piece* board[8][8], int dir) {
// (...)
}
void generateForwardMoves(Pawn p, moveTypes moves, Piece* board[8][8], int dir){
// (...)
}
void generateEnPassantMoves(Pawn p, moveTypes moves, Piece* board[8][8]){
// (...)
}
Things I have tried
- removing the
const
keyword on the void function in the header file - adding const keyword on the functions inside the .cpp file
- removing
const
keyword and replacing with{}
I am at a loss for ideas, can anyone help me out with this?