Possible duplicate:
Undefined symbols "vtable for ..." and "typeinfo for ..."?
C ++ Undefined Link to vtable and inheritance
I have a problem with a small project required from my university. This is a simple chess game project.
I have an unclear error Undefined reference to `vtable for XXX when I define an inherited class from an abstract ... This is the code
Pieces.h
class Pieces { public: Pieces(char color) : pieceColor(color) {} virtual ~Pieces() {} virtual char getPieceType() = 0; char getColor() { return pieceColor; } virtual bool isLegalMove(int srcRow, int srcCol, int destRow, int destCol, Pieces* board[8][8]) = 0; private: virtual bool areSquaresLegal(int srcRow, int srcCol, int destRow, int destCol, Pieces* board[8][8]) = 0; char pieceColor; };
and this is an example of an inherited class, i.e. a pawn
Pawn.h
#include "Pieces.h" class Pawn: public Pieces { public: Pawn(char color) : Pieces(color) {} ~Pawn(); private: virtual char getPieceType() { return 'P'; } bool areSquaresLegal(int srcRow, int srcCol, int destRow, int destCol, Pieces* board[8][8]); bool isLegalMove(int srcRow, int srcCol, int destRow, int destCol, Pieces* board[8][8]); };
The last two methods are implemented in the .cpp file. Obviously, every other class is like a pawn.
When I try to compile, the builder gives me: undefined reference to vtable for Pawn`` with reference to the line in which the constructor:
Pawn(char color) : Pieces(color) {}
Where am I going wrong?